Skip to content

Commit ef0ec48

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 hintShardKey parameter Closes #19494 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent 40c3b70 commit ef0ec48

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,8 @@ 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), ['column' => 'storage', 'value' => $this->getNumericStorageId()]);
398+
if ($insertCount === 0) {
412399
$query = $this->getQueryBuilder();
413400
$query->update('filecache_extended')
414401
->whereFileId($id)

0 commit comments

Comments
 (0)