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

Commit 5e8387a

Browse files
committed
Use received_ts to find uncensored redacted events
Joining against `events` and ordering by `stream_ordering` is inefficient as it forced scanning the entirety of the redactions table. This isn't the case if we use `redactions.received_ts` column as we can then use an index.
1 parent 898dde9 commit 5e8387a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

synapse/storage/events.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,36 +1589,29 @@ def _censor_redactions(self):
15891589
if self.hs.config.redaction_retention_period is None:
15901590
return
15911591

1592-
max_pos = yield self.find_first_stream_ordering_after_ts(
1593-
self._clock.time_msec() - self.hs.config.redaction_retention_period
1594-
)
1592+
before_ts = self._clock.time_msec() - self.hs.config.redaction_retention_period
15951593

15961594
# We fetch all redactions that:
15971595
# 1. point to an event we have,
1598-
# 2. has a stream ordering from before the cut off, and
1596+
# 2. has a received_ts from before the cut off, and
15991597
# 3. we haven't yet censored.
16001598
#
16011599
# This is limited to 100 events to ensure that we don't try and do too
16021600
# much at once. We'll get called again so this should eventually catch
16031601
# up.
1604-
#
1605-
# We use the range [-max_pos, max_pos] to handle backfilled events,
1606-
# which are given negative stream ordering.
16071602
sql = """
1608-
SELECT redact_event.event_id, redacts FROM redactions
1609-
INNER JOIN events AS redact_event USING (event_id)
1603+
SELECT redactions.event_id, redacts FROM redactions
16101604
LEFT JOIN events AS original_event ON (
1611-
redact_event.room_id = original_event.room_id
1612-
AND redacts = original_event.event_id
1605+
redacts = original_event.event_id
16131606
)
16141607
WHERE NOT have_censored
1615-
AND ? <= redact_event.stream_ordering AND redact_event.stream_ordering <= ?
1616-
ORDER BY redact_event.stream_ordering ASC
1608+
AND redactions.received_ts <= ?
1609+
ORDER BY redactions.received_ts ASC
16171610
LIMIT ?
16181611
"""
16191612

16201613
rows = yield self._execute(
1621-
"_censor_redactions_fetch", None, sql, -max_pos, max_pos, 100
1614+
"_censor_redactions_fetch", None, sql, before_ts, 100
16221615
)
16231616

16241617
updates = []

0 commit comments

Comments
 (0)