Issue #2443651 by alexpott, mradcliffe, bzrudi71: PostgreSQL: Fix system\Tests\Cache\DatabaseBackendUnitTest

8.0.x
Nathaniel Catchpole 2015-04-30 17:04:06 +01:00
parent f2ed4ce105
commit c6e77e555a
1 changed files with 41 additions and 32 deletions

View File

@ -202,18 +202,7 @@ class DatabaseBackend implements CacheBackendInterface {
* {@inheritdoc}
*/
public function setMultiple(array $items) {
// Use a transaction so that the database can write the changes in a single
// 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'));
$values = array();
foreach ($items as $cid => $item) {
$item += array(
@ -242,8 +231,28 @@ class DatabaseBackend implements CacheBackendInterface {
$fields['data'] = $item['data'];
$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();