Don't lock user_ips table for upsert.
This commit is contained in:
parent
fabb7acd45
commit
657298cebd
|
@ -104,6 +104,8 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||||
|
|
||||||
self.client_ip_last_seen.prefill(*key + (now,))
|
self.client_ip_last_seen.prefill(*key + (now,))
|
||||||
|
|
||||||
|
# It's safe not to lock here: a) no unique constraint,
|
||||||
|
# b) LAST_SEEN_GRANULARITY makes concurrent updates incredibly unlikely
|
||||||
yield self._simple_upsert(
|
yield self._simple_upsert(
|
||||||
"user_ips",
|
"user_ips",
|
||||||
keyvalues={
|
keyvalues={
|
||||||
|
@ -117,6 +119,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||||
"last_seen": now,
|
"last_seen": now,
|
||||||
},
|
},
|
||||||
desc="insert_client_ip",
|
desc="insert_client_ip",
|
||||||
|
lock=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_user_ip_and_agents(self, user):
|
def get_user_ip_and_agents(self, user):
|
||||||
|
|
|
@ -452,7 +452,7 @@ class SQLBaseStore(object):
|
||||||
txn.execute(sql, values.values())
|
txn.execute(sql, values.values())
|
||||||
|
|
||||||
def _simple_upsert(self, table, keyvalues, values,
|
def _simple_upsert(self, table, keyvalues, values,
|
||||||
insertion_values={}, desc="_simple_upsert"):
|
insertion_values={}, desc="_simple_upsert", lock=True):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
table (str): The table to upsert into
|
table (str): The table to upsert into
|
||||||
|
@ -464,11 +464,14 @@ class SQLBaseStore(object):
|
||||||
return self.runInteraction(
|
return self.runInteraction(
|
||||||
desc,
|
desc,
|
||||||
self._simple_upsert_txn, table, keyvalues, values, insertion_values,
|
self._simple_upsert_txn, table, keyvalues, values, insertion_values,
|
||||||
|
lock
|
||||||
)
|
)
|
||||||
|
|
||||||
def _simple_upsert_txn(self, txn, table, keyvalues, values, insertion_values={}):
|
def _simple_upsert_txn(self, txn, table, keyvalues, values, insertion_values={},
|
||||||
# We need to lock the table :(
|
lock=True):
|
||||||
self.database_engine.lock_table(txn, table)
|
# We need to lock the table :(, unless we're *really* careful
|
||||||
|
if lock:
|
||||||
|
self.database_engine.lock_table(txn, table)
|
||||||
|
|
||||||
# Try to update
|
# Try to update
|
||||||
sql = "UPDATE %s SET %s WHERE %s" % (
|
sql = "UPDATE %s SET %s WHERE %s" % (
|
||||||
|
|
Loading…
Reference in New Issue