diff options
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r-- | synapse/storage/_base.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index e0d97f440b..a6e2e0e2ef 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -440,14 +440,29 @@ class SQLBaseStore(object): ) def _get_events_txn(self, txn, event_ids): - events = [] - for e_id in event_ids: - ev = self._get_event_txn(txn, e_id) + if not event_ids: + return [] - if ev: - events.append(ev) + if len(event_ids) > 50: + events = [] + n = 50 + for e_ids in [event_ids[i:i + n] for i in range(0, len(event_ids), n)]: + events.extend(self._get_events_txn(txn, e_ids)) + return events - return events + where_clause = " OR ".join(["e.event_id = ?" for _ in event_ids]) + + sql = ( + "SELECT internal_metadata, json, r.event_id FROM event_json as e " + "LEFT JOIN redactions as r ON e.event_id = r.redacts " + "WHERE %s" + ) % (where_clause,) + + txn.execute(sql, event_ids) + + res = txn.fetchall() + + return [self._get_event_from_row_txn(txn, *r) for r in res] def _get_event_txn(self, txn, event_id, check_redacted=True, get_prev_content=True): @@ -467,6 +482,13 @@ class SQLBaseStore(object): internal_metadata, js, redacted = res + return self._get_event_from_row_txn( + txn, internal_metadata, js, redacted, check_redacted=check_redacted, + get_prev_content=get_prev_content, + ) + + def _get_event_from_row_txn(self, txn, internal_metadata, js, redacted, + check_redacted=True, get_prev_content=True): d = json.loads(js) internal_metadata = json.loads(internal_metadata) |