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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setMultiple(array $items) {
|
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
|
// 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();
|
$transaction = $this->connection->startTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -213,37 +247,12 @@ class DatabaseBackend implements CacheBackendInterface {
|
||||||
|
|
||||||
$query = $this->connection
|
$query = $this->connection
|
||||||
->insert($this->bin)
|
->insert($this->bin)
|
||||||
->fields(array('cid', 'data', 'expire', 'created', 'serialized', 'tags', 'checksum'));
|
->fields(array('cid', 'expire', 'created', 'tags', 'checksum', 'data', 'serialized'));
|
||||||
|
foreach ($values as $fields) {
|
||||||
foreach ($items as $cid => $item) {
|
// Only pass the values since the order of $fields matches the order of
|
||||||
$item += array(
|
// the insert fields. This is a performance optimization to avoid
|
||||||
'expire' => CacheBackendInterface::CACHE_PERMANENT,
|
// unnecessary loops within the method.
|
||||||
'tags' => array(),
|
$query->values(array_values($fields));
|
||||||
);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
Loading…
Reference in New Issue