diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-10-03 21:43:21 +0200 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2024-10-07 13:23:32 +0200 |
commit | af89838e85a56099fc1c3912b76905b5beeb6f17 (patch) | |
tree | c8c299b458133aca943d1174d4fc88e556468cf4 | |
parent | bbb6cb2eb01937ca5346b30b44e1969eb1eb0807 (diff) | |
download | nextcloud-server-bug/19494/insert-ignore-conflict-for-filecache-extended.tar.gz nextcloud-server-bug/19494/insert-ignore-conflict-for-filecache-extended.zip |
fix: use insert ignore for filecache_extendedbug/19494/insert-ignore-conflict-for-filecache-extended
The current approach is to insert a new row and, if a unique constraint violation occurs, update an existing one. PostgreSQL logs the unique constraint violation as error "duplicate key value violates unique constraint".
Our Adapter.insertIgnoreConflict method provides a way to run an insert query without logging such errors by using the vendor-specific sql extensions like "on conflict do nothing" on Postgres.
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 9a6f7d41faa..56069c88d14 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -359,18 +359,12 @@ class Cache implements ICache { } if (count($extensionValues)) { - try { - $query = $this->getQueryBuilder(); - $query->insert('filecache_extended'); - $query->hintShardKey('storage', $this->getNumericStorageId()); - - $query->setValue('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)); - foreach ($extensionValues as $column => $value) { - $query->setValue($column, $query->createNamedParameter($value)); - } + $insertCount = $this->connection->insertIgnoreConflict( + 'filecache_extended', + array_merge(['fileid' => $id], $extensionValues) + ); - $query->execute(); - } catch (UniqueConstraintViolationException $e) { + if ($insertCount === 0) { $query = $this->getQueryBuilder(); $query->update('filecache_extended') ->whereFileId($id) @@ -386,7 +380,7 @@ class Cache implements ICache { $query->set($key, $query->createNamedParameter($value)); } - $query->execute(); + $query->executeStatement(); } } |