@@ -533,15 +533,14 @@ def __init__(
533
533
if isinstance (self .engine , Sqlite3Engine ):
534
534
self ._unsafe_to_upsert_tables .add ("user_directory_search" )
535
535
536
- if self .engine .can_native_upsert :
537
- # Check ASAP (and then later, every 1s) to see if we have finished
538
- # background updates of tables that aren't safe to update.
539
- self ._clock .call_later (
540
- 0.0 ,
541
- run_as_background_process ,
542
- "upsert_safety_check" ,
543
- self ._check_safe_to_upsert ,
544
- )
536
+ # Check ASAP (and then later, every 1s) to see if we have finished
537
+ # background updates of tables that aren't safe to update.
538
+ self ._clock .call_later (
539
+ 0.0 ,
540
+ run_as_background_process ,
541
+ "upsert_safety_check" ,
542
+ self ._check_safe_to_upsert ,
543
+ )
545
544
546
545
def name (self ) -> str :
547
546
"Return the name of this database"
@@ -1160,11 +1159,8 @@ async def simple_upsert(
1160
1159
attempts = 0
1161
1160
while True :
1162
1161
try :
1163
- # We can autocommit if we are going to use native upserts
1164
- autocommit = (
1165
- self .engine .can_native_upsert
1166
- and table not in self ._unsafe_to_upsert_tables
1167
- )
1162
+ # We can autocommit if it is safe to upsert
1163
+ autocommit = table not in self ._unsafe_to_upsert_tables
1168
1164
1169
1165
return await self .runInteraction (
1170
1166
desc ,
@@ -1199,22 +1195,23 @@ def simple_upsert_txn(
1199
1195
) -> bool :
1200
1196
"""
1201
1197
Pick the UPSERT method which works best on the platform. Either the
1202
- native one (Pg9.5+, recent SQLites ), or fall back to an emulated method.
1198
+ native one (Pg9.5+, SQLite >= 3.24 ), or fall back to an emulated method.
1203
1199
1204
1200
Args:
1205
1201
txn: The transaction to use.
1206
1202
table: The table to upsert into
1207
1203
keyvalues: The unique key tables and their new values
1208
1204
values: The nonunique columns and their new values
1209
1205
insertion_values: additional key/values to use only when inserting
1210
- lock: True to lock the table when doing the upsert.
1206
+ lock: True to lock the table when doing the upsert. Unused when performing
1207
+ a native upsert.
1211
1208
Returns:
1212
1209
Returns True if a row was inserted or updated (i.e. if `values` is
1213
1210
not empty then this always returns True)
1214
1211
"""
1215
1212
insertion_values = insertion_values or {}
1216
1213
1217
- if self . engine . can_native_upsert and table not in self ._unsafe_to_upsert_tables :
1214
+ if table not in self ._unsafe_to_upsert_tables :
1218
1215
return self .simple_upsert_txn_native_upsert (
1219
1216
txn , table , keyvalues , values , insertion_values = insertion_values
1220
1217
)
@@ -1365,14 +1362,12 @@ async def simple_upsert_many(
1365
1362
value_names: The value column names
1366
1363
value_values: A list of each row's value column values.
1367
1364
Ignored if value_names is empty.
1368
- lock: True to lock the table when doing the upsert. Unused if the database engine
1369
- supports native upserts .
1365
+ lock: True to lock the table when doing the upsert. Unused when performing
1366
+ a native upsert .
1370
1367
"""
1371
1368
1372
- # We can autocommit if we are going to use native upserts
1373
- autocommit = (
1374
- self .engine .can_native_upsert and table not in self ._unsafe_to_upsert_tables
1375
- )
1369
+ # We can autocommit if it safe to upsert
1370
+ autocommit = table not in self ._unsafe_to_upsert_tables
1376
1371
1377
1372
await self .runInteraction (
1378
1373
desc ,
@@ -1406,10 +1401,10 @@ def simple_upsert_many_txn(
1406
1401
value_names: The value column names
1407
1402
value_values: A list of each row's value column values.
1408
1403
Ignored if value_names is empty.
1409
- lock: True to lock the table when doing the upsert. Unused if the database engine
1410
- supports native upserts .
1404
+ lock: True to lock the table when doing the upsert. Unused when performing
1405
+ a native upsert .
1411
1406
"""
1412
- if self . engine . can_native_upsert and table not in self ._unsafe_to_upsert_tables :
1407
+ if table not in self ._unsafe_to_upsert_tables :
1413
1408
return self .simple_upsert_many_txn_native_upsert (
1414
1409
txn , table , key_names , key_values , value_names , value_values
1415
1410
)
0 commit comments