diff options
author | Patrick Cloke <patrickc@matrix.org> | 2023-09-29 14:24:54 -0400 |
---|---|---|
committer | Patrick Cloke <patrickc@matrix.org> | 2023-09-29 14:24:54 -0400 |
commit | a280d117dc478e2ea215451ca5ee67b9466dc350 (patch) | |
tree | 41ccdcff112283b2894cf03336a692cade3fd4b8 /synapse/storage/databases | |
parent | Use _do_execute for COPY TO/FROM. (diff) | |
download | synapse-a280d117dc478e2ea215451ca5ee67b9466dc350.tar.xz |
Don't use separate copy_read method.
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r-- | synapse/storage/databases/main/event_federation.py | 76 |
1 files changed, 21 insertions, 55 deletions
diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py index 6d0d8a5402..d4251be7e7 100644 --- a/synapse/storage/databases/main/event_federation.py +++ b/synapse/storage/databases/main/event_federation.py @@ -311,34 +311,16 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas results = set() if isinstance(self.database_engine, PostgresEngine): - if isinstance(self.database_engine, Psycopg2Engine): - # We can use `execute_values` to efficiently fetch the gaps when - # using postgres. - sql = """ - SELECT event_id - FROM event_auth_chains AS c, (VALUES ?) AS l(chain_id, max_seq) - WHERE - c.chain_id = l.chain_id - AND sequence_number <= max_seq - """ - rows = txn.execute_values(sql, chains.items()) - else: - sql = """ - COPY ( - SELECT event_id - FROM event_auth_chains AS c, (VALUES %s) AS l(chain_id, max_seq) - WHERE - c.chain_id = l.chain_id - AND sequence_number <= max_seq - ) - TO STDOUT - """ % ( - ", ".join("(?, ?)" for _ in chains) - ) - # Flatten the arguments. - rows = txn.copy_read( - sql, list(itertools.chain.from_iterable(chains.items())) - ) + # We can use `execute_values` to efficiently fetch the gaps when + # using postgres. + sql = """ + SELECT event_id + FROM event_auth_chains AS c, (VALUES ?) AS l(chain_id, max_seq) + WHERE + c.chain_id = l.chain_id + AND sequence_number <= max_seq + """ + rows = txn.execute_values(sql, chains.items()) results.update(r for r, in rows) else: # For SQLite we just fall back to doing a noddy for loop. @@ -599,38 +581,22 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas return result if isinstance(self.database_engine, PostgresEngine): + # We can use `execute_values` to efficiently fetch the gaps when + # using postgres. + sql = """ + SELECT event_id + FROM event_auth_chains AS c, (VALUES ?) AS l(chain_id, min_seq, max_seq) + WHERE + c.chain_id = l.chain_id + AND min_seq < sequence_number AND sequence_number <= max_seq + """ + args = [ (chain_id, min_no, max_no) for chain_id, (min_no, max_no) in chain_to_gap.items() ] - if isinstance(self.database_engine, Psycopg2Engine): - # We can use `execute_values` to efficiently fetch the gaps when - # using postgres. - sql = """ - SELECT event_id - FROM event_auth_chains AS c, (VALUES ?) AS l(chain_id, min_seq, max_seq) - WHERE - c.chain_id = l.chain_id - AND min_seq < sequence_number AND sequence_number <= max_seq - """ - - rows = txn.execute_values(sql, args) - else: - sql = """ - COPY ( - SELECT event_id - FROM event_auth_chains AS c, (VALUES %s) AS l(chain_id, min_seq, max_seq) - WHERE - c.chain_id = l.chain_id - AND min_seq < sequence_number AND sequence_number <= max_seq - ) - TO STDOUT - """ % ( - ", ".join("(?, ?, ?)" for _ in args) - ) - # Flatten the arguments. - rows = txn.copy_read(sql, list(itertools.chain.from_iterable(args))) + rows = txn.execute_values(sql, args) result.update(r for r, in rows) else: # For SQLite we just fall back to doing a noddy for loop. |