Issue #2443651 by alexpott, mradcliffe, bzrudi71: PostgreSQL: Fix system\Tests\Cache\DatabaseBackendUnitTest
parent
f2ed4ce105
commit
c6e77e555a
|
@ -202,18 +202,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setMultiple(array $items) {
|
public function setMultiple(array $items) {
|
||||||
// Use a transaction so that the database can write the changes in a single
|
$values = array();
|
||||||
// commit.
|
|
||||||
$transaction = $this->connection->startTransaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Delete all items first so we can do one insert. Rather than multiple
|
|
||||||
// merge queries.
|
|
||||||
$this->deleteMultiple(array_keys($items));
|
|
||||||
|
|
||||||
$query = $this->connection
|
|
||||||
->insert($this->bin)
|
|
||||||
->fields(array('cid', 'data', 'expire', 'created', 'serialized', 'tags', 'checksum'));
|
|
||||||
|
|
||||||
foreach ($items as $cid => $item) {
|
foreach ($items as $cid => $item) {
|
||||||
$item += array(
|
$item += array(
|
||||||
|
@ -242,8 +231,28 @@ class DatabaseBackend implements CacheBackendInterface {
|
||||||
$fields['data'] = $item['data'];
|
$fields['data'] = $item['data'];
|
||||||
$fields['serialized'] = 0;
|
$fields['serialized'] = 0;
|
||||||
}
|
}
|
||||||
|
$values[] = $fields;
|
||||||
|
}
|
||||||
|
|
||||||
$query->values($fields);
|
// Use a transaction so that the database can write the changes in a single
|
||||||
|
// 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 {
|
||||||
|
// Delete all items first so we can do one insert. Rather than multiple
|
||||||
|
// merge queries.
|
||||||
|
$this->deleteMultiple(array_keys($items));
|
||||||
|
|
||||||
|
$query = $this->connection
|
||||||
|
->insert($this->bin)
|
||||||
|
->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();
|
$query->execute();
|
||||||
|
|
Loading…
Reference in New Issue