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

Commit

Permalink
Convert _censor_redactions to async since it awaits on coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Dec 10, 2019
1 parent cc5f6eb commit 31da85e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions synapse/storage/data_stores/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,22 +1039,20 @@ def _store_redaction(self, txn, event):
},
)

@defer.inlineCallbacks
def _censor_redactions(self):
async def _censor_redactions(self):
"""Censors all redactions older than the configured period that haven't
been censored yet.
By censor we mean update the event_json table with the redacted event.
Returns:
Deferred
"""

if self.hs.config.redaction_retention_period is None:
return

if self.db.updates.has_completed_background_update(
"redactions_have_censored_ts_idx"
if not (
await self.db.updates.has_completed_background_update(
"redactions_have_censored_ts_idx"
)
):
# We don't want to run this until the appropriate index has been
# created.
Expand All @@ -1081,15 +1079,15 @@ def _censor_redactions(self):
LIMIT ?
"""

rows = yield self.db.execute(
rows = await self.db.execute(
"_censor_redactions_fetch", None, sql, before_ts, 100
)

updates = []

for redaction_id, event_id in rows:
redaction_event = yield self.get_event(redaction_id, allow_none=True)
original_event = yield self.get_event(
redaction_event = await self.get_event(redaction_id, allow_none=True)
original_event = await self.get_event(
event_id, allow_rejected=True, allow_none=True
)

Expand Down Expand Up @@ -1122,7 +1120,7 @@ def _update_censor_txn(txn):
updatevalues={"have_censored": True},
)

yield self.db.runInteraction("_update_censor_txn", _update_censor_txn)
await self.db.runInteraction("_update_censor_txn", _update_censor_txn)

def _censor_event_txn(self, txn, event_id, pruned_json):
"""Censor an event by replacing its JSON in the event_json table with the
Expand Down

0 comments on commit 31da85e

Please sign in to comment.