From 3decf8759494f384e7ca7f0a09a992958ce71390 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Thu, 26 Oct 2023 18:24:43 -0300 Subject: [PATCH] Update core_storage.go --- server/core_storage.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/core_storage.go b/server/core_storage.go index 19ae548c3..35e40ccf3 100644 --- a/server/core_storage.go +++ b/server/core_storage.go @@ -701,7 +701,8 @@ func storagePrepBatch(batch *pgx.Batch, authoritativeWrite bool, op *StorageOpWr SELECT $1, $2, $3, $4, $5, $6, $7, now(), now() WHERE NOT EXISTS(SELECT 1 FROM storage WHERE collection = $1 AND key = $2 AND user_id = $3) -- avoids ON CONFLICT hitting pre-existing object, and immediately cancels insert ON CONFLICT (collection, key, user_id) DO UPDATE - SET version = excluded.version WHERE storage.version = excluded.version AND storage.read = excluded.read AND storage.write = excluded.write -- needed to return a row on concurrent write of same object + SET version = excluded.version + WHERE storage.version = excluded.version AND storage.read = excluded.read AND storage.write = excluded.write -- needed to return a row on concurrent write of same object RETURNING read, write, version, create_time, update_time` // Outcomes: -- GitLab