Commit c6e77e55 authored by catch's avatar catch

Issue #2443651 by alexpott, mradcliffe, bzrudi71: PostgreSQL: Fix...

Issue #2443651 by alexpott, mradcliffe, bzrudi71: PostgreSQL: Fix system\Tests\Cache\DatabaseBackendUnitTest
parent f2ed4ce1
......@@ -202,8 +202,42 @@ protected function doSet($cid, $data, $expire, $tags) {
* {@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 @@ public function setMultiple(array $items) {
$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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment