Skip to content

Commit 86ac08b

Browse files
committed
feat(cache): use the insertIgnoreConflict connexion method so that conflicts are properly handled
In the FileCache, use insertIgnoreConflict to avoid conflict error messages on PostgreSQL. Use the new optional callback argument to hintShardKey even though insertIgnoreConflict doesn't support that Closes #19494 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent 3d21e9d commit 86ac08b

1 file changed

Lines changed: 3 additions & 32 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -394,38 +394,9 @@ public function update($id, array $data) {
394394
}
395395

396396
if (count($extensionValues)) {
397-
try {
398-
$query = $this->getQueryBuilder();
399-
$query->insert('filecache_extended');
400-
$query->hintShardKey('storage', $this->getNumericStorageId());
401-
402-
$query->setValue('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT));
403-
foreach ($extensionValues as $column => $value) {
404-
$query->setValue($column, $query->createNamedParameter($value));
405-
}
406-
407-
$query->executeStatement();
408-
} catch (Exception $e) {
409-
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
410-
throw $e;
411-
}
412-
$query = $this->getQueryBuilder();
413-
$query->update('filecache_extended')
414-
->whereFileId($id)
415-
->hintShardKey('storage', $this->getNumericStorageId())
416-
->andWhere($query->expr()->orX(...array_map(function ($key, $value) use ($query) {
417-
return $query->expr()->orX(
418-
$query->expr()->neq($key, $query->createNamedParameter($value)),
419-
$query->expr()->isNull($key)
420-
);
421-
}, array_keys($extensionValues), array_values($extensionValues))));
422-
423-
foreach ($extensionValues as $key => $value) {
424-
$query->set($key, $query->createNamedParameter($value));
425-
}
426-
427-
$query->executeStatement();
428-
}
397+
$this->connection->insertIgnoreConflict('filecache_extended', array_merge(['fileid' => $id], $extensionValues), function (IQueryBuilder $queryCallback) {
398+
$queryCallback->hintShardKey('storage', $this->getNumericStorageId());
399+
});
429400
}
430401

431402
$path = $this->getPathById($id);

0 commit comments

Comments
 (0)