Issue #2443651 by alexpott, mradcliffe, bzrudi71: PostgreSQL: Fix system\Tests\Cache\DatabaseBackendUnitTest
parent
f2ed4ce105
commit
c6e77e555a
|
@ -202,8 +202,42 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function setMultiple(array $items) {
|
||||
$values = array();
|
||||
|
||||
foreach ($items as $cid => $item) {
|
||||
$item += array(
|
||||
'expire' => CacheBackendInterface::CACHE_PERMANENT,
|
||||
'tags' => array(),
|
||||
);
|
||||
|
||||
Cache::validateTags($item['tags']);
|
||||
$item['tags'] = array_unique($item['tags']);
|
||||
// Sort the cache tags so that they are stored consistently in the DB.
|
||||
sort($item['tags']);
|
||||
|
||||
$fields = array(
|
||||
'cid' => $cid,
|
||||
'expire' => $item['expire'],
|
||||
'created' => round(microtime(TRUE), 3),
|
||||
'tags' => implode(' ', $item['tags']),
|
||||
'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']),
|
||||
);
|
||||
|
||||
if (!is_string($item['data'])) {
|
||||
$fields['data'] = serialize($item['data']);
|
||||
$fields['serialized'] = 1;
|
||||
}
|
||||
else {
|
||||
$fields['data'] = $item['data'];
|
||||
$fields['serialized'] = 0;
|
||||
}
|
||||
$values[] = $fields;
|
||||
}
|
||||
|
||||
// Use a transaction so that the database can write the changes in a single
|
||||
// commit.
|
||||
// commit. The transaction is started after calculating the tag checksums
|
||||
// since that can create a table and this causes an exception when using
|
||||
// PostgreSQL.
|
||||
$transaction = $this->connection->startTransaction();
|
||||
|
||||
try {
|
||||
|
@ -213,37 +247,12 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
|
||||
$query = $this->connection
|
||||
->insert($this->bin)
|
||||
->fields(array('cid', 'data', 'expire', 'created', 'serialized', 'tags', 'checksum'));
|
||||
|
||||
foreach ($items as $cid => $item) {
|
||||
$item += array(
|
||||
'expire' => CacheBackendInterface::CACHE_PERMANENT,
|
||||
'tags' => array(),
|
||||
);
|
||||
|
||||
Cache::validateTags($item['tags']);
|
||||
$item['tags'] = array_unique($item['tags']);
|
||||
// Sort the cache tags so that they are stored consistently in the DB.
|
||||
sort($item['tags']);
|
||||
|
||||
$fields = array(
|
||||
'cid' => $cid,
|
||||
'expire' => $item['expire'],
|
||||
'created' => round(microtime(TRUE), 3),
|
||||
'tags' => implode(' ', $item['tags']),
|
||||
'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']),
|
||||
);
|
||||
|
||||
if (!is_string($item['data'])) {
|
||||
$fields['data'] = serialize($item['data']);
|
||||
$fields['serialized'] = 1;
|
||||
}
|
||||
else {
|
||||
$fields['data'] = $item['data'];
|
||||
$fields['serialized'] = 0;
|
||||
}
|
||||
|
||||
$query->values($fields);
|
||||
->fields(array('cid', 'expire', 'created', 'tags', 'checksum', 'data', 'serialized'));
|
||||
foreach ($values as $fields) {
|
||||
// Only pass the values since the order of $fields matches the order of
|
||||
// the insert fields. This is a performance optimization to avoid
|
||||
// unnecessary loops within the method.
|
||||
$query->values(array_values($fields));
|
||||
}
|
||||
|
||||
$query->execute();
|
||||
|
|
Loading…
Reference in New Issue