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

Commit e726e18

Browse files
authored
Merge pull request #6499 from matrix-org/erikj/fix_sqlite_7
Fix support for SQLite 3.7.
2 parents e3f528c + 5234699 commit e726e18

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

changelog.d/6499.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix support for SQLite 3.7.

synapse/storage/data_stores/main/events.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,20 +1039,25 @@ def _store_redaction(self, txn, event):
10391039
},
10401040
)
10411041

1042-
@defer.inlineCallbacks
1043-
def _censor_redactions(self):
1042+
async def _censor_redactions(self):
10441043
"""Censors all redactions older than the configured period that haven't
10451044
been censored yet.
10461045
10471046
By censor we mean update the event_json table with the redacted event.
1048-
1049-
Returns:
1050-
Deferred
10511047
"""
10521048

10531049
if self.hs.config.redaction_retention_period is None:
10541050
return
10551051

1052+
if not (
1053+
await self.db.updates.has_completed_background_update(
1054+
"redactions_have_censored_ts_idx"
1055+
)
1056+
):
1057+
# We don't want to run this until the appropriate index has been
1058+
# created.
1059+
return
1060+
10561061
before_ts = self._clock.time_msec() - self.hs.config.redaction_retention_period
10571062

10581063
# We fetch all redactions that:
@@ -1074,15 +1079,15 @@ def _censor_redactions(self):
10741079
LIMIT ?
10751080
"""
10761081

1077-
rows = yield self.db.execute(
1082+
rows = await self.db.execute(
10781083
"_censor_redactions_fetch", None, sql, before_ts, 100
10791084
)
10801085

10811086
updates = []
10821087

10831088
for redaction_id, event_id in rows:
1084-
redaction_event = yield self.get_event(redaction_id, allow_none=True)
1085-
original_event = yield self.get_event(
1089+
redaction_event = await self.get_event(redaction_id, allow_none=True)
1090+
original_event = await self.get_event(
10861091
event_id, allow_rejected=True, allow_none=True
10871092
)
10881093

@@ -1115,7 +1120,7 @@ def _update_censor_txn(txn):
11151120
updatevalues={"have_censored": True},
11161121
)
11171122

1118-
yield self.db.runInteraction("_update_censor_txn", _update_censor_txn)
1123+
await self.db.runInteraction("_update_censor_txn", _update_censor_txn)
11191124

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

synapse/storage/data_stores/main/events_bg_updates.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def __init__(self, database: Database, db_conn, hs):
9090
"event_store_labels", self._event_store_labels
9191
)
9292

93+
self.db.updates.register_background_index_update(
94+
"redactions_have_censored_ts_idx",
95+
index_name="redactions_have_censored_ts",
96+
table="redactions",
97+
columns=["received_ts"],
98+
where_clause="NOT have_censored",
99+
)
100+
93101
@defer.inlineCallbacks
94102
def _background_reindex_fields_sender(self, progress, batch_size):
95103
target_min_stream_id = progress["target_min_stream_id_inclusive"]

synapse/storage/data_stores/main/schema/delta/56/redaction_censor.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@
1414
*/
1515

1616
ALTER TABLE redactions ADD COLUMN have_censored BOOL NOT NULL DEFAULT false;
17-
CREATE INDEX redactions_have_censored ON redactions(event_id) WHERE not have_censored;

synapse/storage/data_stores/main/schema/delta/56/redaction_censor2.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*/
1515

1616
ALTER TABLE redactions ADD COLUMN received_ts BIGINT;
17-
CREATE INDEX redactions_have_censored_ts ON redactions(received_ts) WHERE not have_censored;
1817

1918
INSERT INTO background_updates (update_name, progress_json) VALUES
2019
('redactions_received_ts', '{}');
20+
21+
INSERT INTO background_updates (update_name, progress_json) VALUES
22+
('redactions_have_censored_ts_idx', '{}');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Copyright 2019 The Matrix.org Foundation C.I.C.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
DROP INDEX IF EXISTS redactions_have_censored;

0 commit comments

Comments
 (0)