0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 17:03:50 +01:00

Add more data to the event_labels table and fix the indexes

This commit is contained in:
Brendan Abolivier 2019-11-01 11:47:28 +00:00
parent e3689ac6f7
commit a2c63c619a
No known key found for this signature in database
GPG key ID: 1E015C145F1916CD
3 changed files with 21 additions and 5 deletions

View file

@ -1493,7 +1493,9 @@ class EventsStore(
# Store the labels for this event.
labels = event.content.get(EventContentFields.Labels)
if labels:
self.insert_labels_for_event_txn(txn, event.event_id, labels)
self.insert_labels_for_event_txn(
txn, event.event_id, labels, event.room_id, event.depth
)
# Insert into the room_memberships table.
self._store_room_members_txn(
@ -2482,7 +2484,9 @@ class EventsStore(
get_all_updated_current_state_deltas_txn,
)
def insert_labels_for_event_txn(self, txn, event_id, labels):
def insert_labels_for_event_txn(
self, txn, event_id, labels, room_id, topological_ordering
):
"""Store the mapping between an event's ID and its labels, with one row per
(event_id, label) tuple.
@ -2490,11 +2494,21 @@ class EventsStore(
txn (LoggingTransaction): The transaction to execute.
event_id (str): The event's ID.
labels (list[str]): A list of text labels.
room_id (str): The ID of the room the event was sent to.
topological_ordering (int): The position of the event in the room's topology.
"""
return self._simple_insert_many_txn(
txn=txn,
table="event_labels",
values=[{"event_id": event_id, "label": label} for label in labels],
values=[
{
"event_id": event_id,
"label": label,
"room_id": room_id,
"topological_ordering": topological_ordering,
}
for label in labels
],
)

View file

@ -16,7 +16,9 @@
CREATE TABLE IF NOT EXISTS event_labels (
event_id TEXT,
label TEXT,
room_id TEXT NOT NULL,
topological_ordering bigint NOT NULL,
PRIMARY KEY(event_id, label)
);
CREATE INDEX event_labels_label_idx ON event_labels(label);
CREATE INDEX event_labels_room_id_label_idx ON event_labels(room_id, label, topological_ordering);

View file

@ -874,7 +874,7 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
sql = (
"SELECT DISTINCT event_id, topological_ordering, stream_ordering"
" FROM events"
" LEFT JOIN event_labels USING (event_id)"
" LEFT JOIN event_labels USING (event_id, room_id, topological_ordering)"
" WHERE outlier = ? AND room_id = ? AND %(bounds)s"
" ORDER BY topological_ordering %(order)s,"
" stream_ordering %(order)s LIMIT ?"