Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Minor perf fixes to get_auth_chain_ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Feb 19, 2020
1 parent fc87d2f commit 7b7c3ce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/6954.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor perf fixes to `get_auth_chain_ids`.
10 changes: 4 additions & 6 deletions synapse/storage/data_stores/main/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import logging
from typing import List, Optional, Set

from six.moves import range
from six.moves.queue import Empty, PriorityQueue

from twisted.internet import defer
Expand All @@ -28,6 +27,7 @@
from synapse.storage.data_stores.main.signatures import SignatureWorkerStore
from synapse.storage.database import Database
from synapse.util.caches.descriptors import cached
from synapse.util.iterutils import batch_iter

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,14 +88,12 @@ def _get_auth_chain_ids_txn(self, txn, event_ids, include_given, ignore_events):
front = set(event_ids)
while front:
new_front = set()
front_list = list(front)
chunks = [front_list[x : x + 100] for x in range(0, len(front), 100)]
for chunk in chunks:
for chunk in batch_iter(front, 100):
clause, args = make_in_list_sql_clause(
txn.database_engine, "event_id", chunk
)
txn.execute(base_sql + clause, list(args))
new_front.update([r[0] for r in txn])
txn.execute(base_sql + clause, args)
new_front.update(r[0] for r in txn)

new_front -= ignore_events
new_front -= results
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ def simple_search_list_txn(cls, txn, table, term, col, retcols):

def make_in_list_sql_clause(
database_engine, column: str, iterable: Iterable
) -> Tuple[str, Iterable]:
) -> Tuple[str, list]:
"""Returns an SQL clause that checks the given column is in the iterable.
On SQLite this expands to `column IN (?, ?, ...)`, whereas on Postgres
Expand Down

0 comments on commit 7b7c3ce

Please sign in to comment.