Compare commits

...

5 Commits

Author SHA1 Message Date
Erik Johnston
1da0457bba pep 2020-02-19 15:21:53 +00:00
Erik Johnston
59f1458958 Use batch_iter and drop conversion to list 2020-02-19 15:15:51 +00:00
Erik Johnston
cb8fdfdf1c Mark make_in_list_sql_clause as returning a list 2020-02-19 15:13:51 +00:00
Erik Johnston
7cadb476a0 Newsfile 2020-02-19 13:57:30 +00:00
Erik Johnston
008aaca0b6 Minor perf fixes to get_auth_chain_ids 2020-02-19 13:56:15 +00:00
3 changed files with 6 additions and 7 deletions

1
changelog.d/6954.misc Normal file
View File

@@ -0,0 +1 @@
Minor perf fixes to `get_auth_chain_ids`.

View File

@@ -15,7 +15,6 @@
import itertools
import logging
from six.moves import range
from six.moves.queue import Empty, PriorityQueue
from twisted.internet import defer
@@ -27,6 +26,7 @@ from synapse.storage.data_stores.main.events_worker import EventsWorkerStore
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__)
@@ -71,14 +71,12 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas
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 -= results

View File

@@ -1504,7 +1504,7 @@ class Database(object):
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