|
|
|
@ -22,13 +22,12 @@ from canonicaljson import json |
|
|
|
|
from twisted.internet import defer |
|
|
|
|
|
|
|
|
|
from synapse.api.constants import EventContentFields |
|
|
|
|
from synapse.storage._base import make_in_list_sql_clause |
|
|
|
|
from synapse.storage.background_updates import BackgroundUpdateStore |
|
|
|
|
from synapse.storage._base import SQLBaseStore, make_in_list_sql_clause |
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
class EventsBackgroundUpdatesStore(SQLBaseStore): |
|
|
|
|
|
|
|
|
|
EVENT_ORIGIN_SERVER_TS_NAME = "event_origin_server_ts" |
|
|
|
|
EVENT_FIELDS_SENDER_URL_UPDATE_NAME = "event_fields_sender_url" |
|
|
|
@ -37,15 +36,15 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
def __init__(self, db_conn, hs): |
|
|
|
|
super(EventsBackgroundUpdatesStore, self).__init__(db_conn, hs) |
|
|
|
|
|
|
|
|
|
self.register_background_update_handler( |
|
|
|
|
self.db.updates.register_background_update_handler( |
|
|
|
|
self.EVENT_ORIGIN_SERVER_TS_NAME, self._background_reindex_origin_server_ts |
|
|
|
|
) |
|
|
|
|
self.register_background_update_handler( |
|
|
|
|
self.db.updates.register_background_update_handler( |
|
|
|
|
self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME, |
|
|
|
|
self._background_reindex_fields_sender, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
self.register_background_index_update( |
|
|
|
|
self.db.updates.register_background_index_update( |
|
|
|
|
"event_contains_url_index", |
|
|
|
|
index_name="event_contains_url_index", |
|
|
|
|
table="events", |
|
|
|
@ -56,7 +55,7 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
# an event_id index on event_search is useful for the purge_history |
|
|
|
|
# api. Plus it means we get to enforce some integrity with a UNIQUE |
|
|
|
|
# clause |
|
|
|
|
self.register_background_index_update( |
|
|
|
|
self.db.updates.register_background_index_update( |
|
|
|
|
"event_search_event_id_idx", |
|
|
|
|
index_name="event_search_event_id_idx", |
|
|
|
|
table="event_search", |
|
|
|
@ -65,16 +64,16 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
psql_only=True, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
self.register_background_update_handler( |
|
|
|
|
self.db.updates.register_background_update_handler( |
|
|
|
|
self.DELETE_SOFT_FAILED_EXTREMITIES, self._cleanup_extremities_bg_update |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
self.register_background_update_handler( |
|
|
|
|
self.db.updates.register_background_update_handler( |
|
|
|
|
"redactions_received_ts", self._redactions_received_ts |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# This index gets deleted in `event_fix_redactions_bytes` update |
|
|
|
|
self.register_background_index_update( |
|
|
|
|
self.db.updates.register_background_index_update( |
|
|
|
|
"event_fix_redactions_bytes_create_index", |
|
|
|
|
index_name="redactions_censored_redacts", |
|
|
|
|
table="redactions", |
|
|
|
@ -82,11 +81,11 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
where_clause="have_censored", |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
self.register_background_update_handler( |
|
|
|
|
self.db.updates.register_background_update_handler( |
|
|
|
|
"event_fix_redactions_bytes", self._event_fix_redactions_bytes |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
self.register_background_update_handler( |
|
|
|
|
self.db.updates.register_background_update_handler( |
|
|
|
|
"event_store_labels", self._event_store_labels |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -145,7 +144,7 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
"rows_inserted": rows_inserted + len(rows), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self._background_update_progress_txn( |
|
|
|
|
self.db.updates._background_update_progress_txn( |
|
|
|
|
txn, self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME, progress |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -156,7 +155,9 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not result: |
|
|
|
|
yield self._end_background_update(self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME) |
|
|
|
|
yield self.db.updates._end_background_update( |
|
|
|
|
self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
@ -222,7 +223,7 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
"rows_inserted": rows_inserted + len(rows_to_update), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self._background_update_progress_txn( |
|
|
|
|
self.db.updates._background_update_progress_txn( |
|
|
|
|
txn, self.EVENT_ORIGIN_SERVER_TS_NAME, progress |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -233,7 +234,9 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not result: |
|
|
|
|
yield self._end_background_update(self.EVENT_ORIGIN_SERVER_TS_NAME) |
|
|
|
|
yield self.db.updates._end_background_update( |
|
|
|
|
self.EVENT_ORIGIN_SERVER_TS_NAME |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
@ -411,7 +414,9 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not num_handled: |
|
|
|
|
yield self._end_background_update(self.DELETE_SOFT_FAILED_EXTREMITIES) |
|
|
|
|
yield self.db.updates._end_background_update( |
|
|
|
|
self.DELETE_SOFT_FAILED_EXTREMITIES |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def _drop_table_txn(txn): |
|
|
|
|
txn.execute("DROP TABLE _extremities_to_check") |
|
|
|
@ -464,7 +469,7 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
|
|
|
|
|
txn.execute(sql, (self._clock.time_msec(), last_event_id, upper_event_id)) |
|
|
|
|
|
|
|
|
|
self._background_update_progress_txn( |
|
|
|
|
self.db.updates._background_update_progress_txn( |
|
|
|
|
txn, "redactions_received_ts", {"last_event_id": upper_event_id} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -475,7 +480,7 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not count: |
|
|
|
|
yield self._end_background_update("redactions_received_ts") |
|
|
|
|
yield self.db.updates._end_background_update("redactions_received_ts") |
|
|
|
|
|
|
|
|
|
return count |
|
|
|
|
|
|
|
|
@ -505,7 +510,7 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
"_event_fix_redactions_bytes", _event_fix_redactions_bytes_txn |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
yield self._end_background_update("event_fix_redactions_bytes") |
|
|
|
|
yield self.db.updates._end_background_update("event_fix_redactions_bytes") |
|
|
|
|
|
|
|
|
|
return 1 |
|
|
|
|
|
|
|
|
@ -559,7 +564,7 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
nbrows += 1 |
|
|
|
|
last_row_event_id = event_id |
|
|
|
|
|
|
|
|
|
self._background_update_progress_txn( |
|
|
|
|
self.db.updates._background_update_progress_txn( |
|
|
|
|
txn, "event_store_labels", {"last_event_id": last_row_event_id} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -570,6 +575,6 @@ class EventsBackgroundUpdatesStore(BackgroundUpdateStore): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not num_rows: |
|
|
|
|
yield self._end_background_update("event_store_labels") |
|
|
|
|
yield self.db.updates._end_background_update("event_store_labels") |
|
|
|
|
|
|
|
|
|
return num_rows |
|
|
|
|