mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-12 10:42:16 -04:00
Move DB pool and helper functions into dedicated Database class
This commit is contained in:
parent
ddbbfc9512
commit
756d4942f5
62 changed files with 2377 additions and 2295 deletions
|
@ -61,7 +61,7 @@ class ReceiptsWorkerStore(SQLBaseStore):
|
|||
|
||||
@cached(num_args=2)
|
||||
def get_receipts_for_room(self, room_id, receipt_type):
|
||||
return self.simple_select_list(
|
||||
return self.db.simple_select_list(
|
||||
table="receipts_linearized",
|
||||
keyvalues={"room_id": room_id, "receipt_type": receipt_type},
|
||||
retcols=("user_id", "event_id"),
|
||||
|
@ -70,7 +70,7 @@ class ReceiptsWorkerStore(SQLBaseStore):
|
|||
|
||||
@cached(num_args=3)
|
||||
def get_last_receipt_event_id_for_user(self, user_id, room_id, receipt_type):
|
||||
return self.simple_select_one_onecol(
|
||||
return self.db.simple_select_one_onecol(
|
||||
table="receipts_linearized",
|
||||
keyvalues={
|
||||
"room_id": room_id,
|
||||
|
@ -84,7 +84,7 @@ class ReceiptsWorkerStore(SQLBaseStore):
|
|||
|
||||
@cachedInlineCallbacks(num_args=2)
|
||||
def get_receipts_for_user(self, user_id, receipt_type):
|
||||
rows = yield self.simple_select_list(
|
||||
rows = yield self.db.simple_select_list(
|
||||
table="receipts_linearized",
|
||||
keyvalues={"user_id": user_id, "receipt_type": receipt_type},
|
||||
retcols=("room_id", "event_id"),
|
||||
|
@ -108,7 +108,7 @@ class ReceiptsWorkerStore(SQLBaseStore):
|
|||
txn.execute(sql, (user_id,))
|
||||
return txn.fetchall()
|
||||
|
||||
rows = yield self.runInteraction("get_receipts_for_user_with_orderings", f)
|
||||
rows = yield self.db.runInteraction("get_receipts_for_user_with_orderings", f)
|
||||
return {
|
||||
row[0]: {
|
||||
"event_id": row[1],
|
||||
|
@ -187,11 +187,11 @@ class ReceiptsWorkerStore(SQLBaseStore):
|
|||
|
||||
txn.execute(sql, (room_id, to_key))
|
||||
|
||||
rows = self.cursor_to_dict(txn)
|
||||
rows = self.db.cursor_to_dict(txn)
|
||||
|
||||
return rows
|
||||
|
||||
rows = yield self.runInteraction("get_linearized_receipts_for_room", f)
|
||||
rows = yield self.db.runInteraction("get_linearized_receipts_for_room", f)
|
||||
|
||||
if not rows:
|
||||
return []
|
||||
|
@ -237,9 +237,11 @@ class ReceiptsWorkerStore(SQLBaseStore):
|
|||
|
||||
txn.execute(sql + clause, [to_key] + list(args))
|
||||
|
||||
return self.cursor_to_dict(txn)
|
||||
return self.db.cursor_to_dict(txn)
|
||||
|
||||
txn_results = yield self.runInteraction("_get_linearized_receipts_for_rooms", f)
|
||||
txn_results = yield self.db.runInteraction(
|
||||
"_get_linearized_receipts_for_rooms", f
|
||||
)
|
||||
|
||||
results = {}
|
||||
for row in txn_results:
|
||||
|
@ -282,7 +284,7 @@ class ReceiptsWorkerStore(SQLBaseStore):
|
|||
|
||||
return list(r[0:5] + (json.loads(r[5]),) for r in txn)
|
||||
|
||||
return self.runInteraction(
|
||||
return self.db.runInteraction(
|
||||
"get_all_updated_receipts", get_all_updated_receipts_txn
|
||||
)
|
||||
|
||||
|
@ -335,7 +337,7 @@ class ReceiptsStore(ReceiptsWorkerStore):
|
|||
otherwise, the rx timestamp of the event that the RR corresponds to
|
||||
(or 0 if the event is unknown)
|
||||
"""
|
||||
res = self.simple_select_one_txn(
|
||||
res = self.db.simple_select_one_txn(
|
||||
txn,
|
||||
table="events",
|
||||
retcols=["stream_ordering", "received_ts"],
|
||||
|
@ -388,7 +390,7 @@ class ReceiptsStore(ReceiptsWorkerStore):
|
|||
(user_id, room_id, receipt_type),
|
||||
)
|
||||
|
||||
self.simple_delete_txn(
|
||||
self.db.simple_delete_txn(
|
||||
txn,
|
||||
table="receipts_linearized",
|
||||
keyvalues={
|
||||
|
@ -398,7 +400,7 @@ class ReceiptsStore(ReceiptsWorkerStore):
|
|||
},
|
||||
)
|
||||
|
||||
self.simple_insert_txn(
|
||||
self.db.simple_insert_txn(
|
||||
txn,
|
||||
table="receipts_linearized",
|
||||
values={
|
||||
|
@ -453,13 +455,13 @@ class ReceiptsStore(ReceiptsWorkerStore):
|
|||
else:
|
||||
raise RuntimeError("Unrecognized event_ids: %r" % (event_ids,))
|
||||
|
||||
linearized_event_id = yield self.runInteraction(
|
||||
linearized_event_id = yield self.db.runInteraction(
|
||||
"insert_receipt_conv", graph_to_linear
|
||||
)
|
||||
|
||||
stream_id_manager = self._receipts_id_gen.get_next()
|
||||
with stream_id_manager as stream_id:
|
||||
event_ts = yield self.runInteraction(
|
||||
event_ts = yield self.db.runInteraction(
|
||||
"insert_linearized_receipt",
|
||||
self.insert_linearized_receipt_txn,
|
||||
room_id,
|
||||
|
@ -488,7 +490,7 @@ class ReceiptsStore(ReceiptsWorkerStore):
|
|||
return stream_id, max_persisted_id
|
||||
|
||||
def insert_graph_receipt(self, room_id, receipt_type, user_id, event_ids, data):
|
||||
return self.runInteraction(
|
||||
return self.db.runInteraction(
|
||||
"insert_graph_receipt",
|
||||
self.insert_graph_receipt_txn,
|
||||
room_id,
|
||||
|
@ -514,7 +516,7 @@ class ReceiptsStore(ReceiptsWorkerStore):
|
|||
self._get_linearized_receipts_for_room.invalidate_many, (room_id,)
|
||||
)
|
||||
|
||||
self.simple_delete_txn(
|
||||
self.db.simple_delete_txn(
|
||||
txn,
|
||||
table="receipts_graph",
|
||||
keyvalues={
|
||||
|
@ -523,7 +525,7 @@ class ReceiptsStore(ReceiptsWorkerStore):
|
|||
"user_id": user_id,
|
||||
},
|
||||
)
|
||||
self.simple_insert_txn(
|
||||
self.db.simple_insert_txn(
|
||||
txn,
|
||||
table="receipts_graph",
|
||||
values={
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue