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

Fix support for SQLite 3.7. #6499

Merged
merged 5 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6499.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix support for SQLite 3.7.
7 changes: 7 additions & 0 deletions synapse/storage/data_stores/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,13 @@ def _censor_redactions(self):
if self.hs.config.redaction_retention_period is None:
return

if self.db.updates.has_completed_background_update(
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
"redactions_have_censored_ts_idx"
):
# We don't want to run this until the appropriate index has been
# created.
return

before_ts = self._clock.time_msec() - self.hs.config.redaction_retention_period

# We fetch all redactions that:
Expand Down
16 changes: 16 additions & 0 deletions synapse/storage/data_stores/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ def __init__(self, database: Database, db_conn, hs):
"event_store_labels", self._event_store_labels
)

self.db.updates.register_background_index_update(
"redactions_have_censored_idx",
index_name="redactions_have_censored",
table="redactions",
columns=["event_id"],
where_clause="NOT have_censored",
)

self.db.updates.register_background_index_update(
"redactions_have_censored_ts_idx",
index_name="redactions_have_censored_ts",
table="redactions",
columns=["received_ts"],
where_clause="NOT have_censored",
)

@defer.inlineCallbacks
def _background_reindex_fields_sender(self, progress, batch_size):
target_min_stream_id = progress["target_min_stream_id_inclusive"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
*/

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

INSERT INTO background_updates (update_name, progress_json) VALUES
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
('redactions_have_censored_idx', '{}');
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
*/

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

INSERT INTO background_updates (update_name, progress_json) VALUES
('redactions_received_ts', '{}');

INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
('redactions_have_censored_ts_idx', '{}', 'redactions_have_censored_idx');