mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 01:24:48 -04:00
Replace or_ignore
in simple_insert
with simple_upsert
(#10442)
Now that we have `simple_upsert` that should be used in preference to trying to insert and looking for an exception. The main benefit is that we ERROR message don't get written to postgres logs. We also have tidy up the return value on `simple_upsert`, rather than having a tri-state of inserted/not-inserted/unknown.
This commit is contained in:
parent
d8324b8238
commit
38b346a504
6 changed files with 44 additions and 99 deletions
|
@ -1078,16 +1078,18 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
|
|||
return False
|
||||
|
||||
try:
|
||||
inserted = await self.db_pool.simple_insert(
|
||||
inserted = await self.db_pool.simple_upsert(
|
||||
"devices",
|
||||
values={
|
||||
keyvalues={
|
||||
"user_id": user_id,
|
||||
"device_id": device_id,
|
||||
},
|
||||
values={},
|
||||
insertion_values={
|
||||
"display_name": initial_device_display_name,
|
||||
"hidden": False,
|
||||
},
|
||||
desc="store_device",
|
||||
or_ignore=True,
|
||||
)
|
||||
if not inserted:
|
||||
# if the device already exists, check if it's a real device, or
|
||||
|
@ -1099,6 +1101,7 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
|
|||
)
|
||||
if hidden:
|
||||
raise StoreError(400, "The device ID is in use", Codes.FORBIDDEN)
|
||||
|
||||
self.device_id_exists_cache.set(key, True)
|
||||
return inserted
|
||||
except StoreError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue