Skip to content

Commit d821eb2

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 d821eb2

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,10 @@ 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-
}
397+
$insertCount = $this->connection->insertIgnoreConflict('filecache_extended', array_merge(['fileid' => $id], $extensionValues), function (IQueryBuilder $queryCallback) {
398+
$queryCallback->hintShardKey('storage', $this->getNumericStorageId());
399+
});
400+
if ($insertCount === 0) {
412401
$query = $this->getQueryBuilder();
413402
$query->update('filecache_extended')
414403
->whereFileId($id)

0 commit comments

Comments
 (0)