-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make historical events discoverable from backfill for servers without any scrollback history (MSC2716) (federation) #10245
Changes from 22 commits
d2e2aa7
2d942ec
38bcf13
e405a23
36f1565
05d6c51
defc536
dfad8a8
7d850db
164dee4
04b1f7e
b703962
8c205e5
7b8b2d1
281588f
4226165
baae5d8
c05e43b
02b1bea
66cf5be
ab8011b
f20ba02
64aeb73
ea7c30d
9a6fd3f
0f6179f
5970e3f
bc13396
669da52
9a86e05
8999567
35a4569
b2be8ce
04a29fe
258fa57
9352635
5c454b7
e881cff
c9330ec
a8c5311
ae606c7
bc896cc
f231066
465b3d8
44bb3f0
4d936b5
706770c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1504,6 +1504,9 @@ def _update_metadata_tables_txn( | |
|
||
self._handle_event_relations(txn, event) | ||
|
||
self._handle_insertion_event(txn, event) | ||
self._handle_chunk_id(txn, event) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the best place to limit who can add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want to reject such events, so we probably want to add some stuff to the event authorization code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am having trouble fitting this into the existing code.
def _check_if_allowed_to_send_historical_events def _check_if_allowed_to_send_historical_events(
self,
event: EventBase,
):
"""Check whether the event sender is allowed to add insertion, marker,
or events with a chunk ID
Raises:
AuthError if the event sender is not an application service
"""
if (
event.type != EventTypes.MSC2716_INSERTION
and event.type != EventTypes.MSC2716_MARKER
and event.content.get(EventContentFields.MSC2716_CHUNK_ID) is None
):
pass
app_service = self._store.get_app_service_by_user_id(event.sender)
if app_service is None:
raise AuthError(403, "Only application services can send insertion events") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the But we would probably want to default the power level for those events in existing rooms which don't have it set yet. Maybe default to only the creator or admins can do it if not explicitly set in power levels. Or keep it simple and not allow the history based events at all unless the power level was set. Is there any precedent for this? There is The one problem I see is that there doesn't seem to be precedent for controlling a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added unstable room version I switched to |
||
|
||
# Store the labels for this event. | ||
labels = event.content.get(EventContentFields.LABELS) | ||
if labels: | ||
|
@@ -1756,6 +1759,75 @@ def _handle_event_relations(self, txn, event): | |
if rel_type == RelationTypes.REPLACE: | ||
txn.call_after(self.store.get_applicable_edit.invalidate, (parent_id,)) | ||
|
||
def _handle_insertion_event(self, txn: LoggingTransaction, event: EventBase): | ||
"""Handles inserting insertion extremeties during peristence of marker events | ||
|
||
Args: | ||
txn: The database transaction object | ||
event: The event to process | ||
""" | ||
|
||
if event.type != EventTypes.MSC2716_INSERTION: | ||
# Not a insertion event | ||
return | ||
|
||
logger.debug("_handle_insertion_event %s", event) | ||
|
||
next_chunk_id = event.content.get(EventContentFields.MSC2716_NEXT_CHUNK_ID) | ||
if next_chunk_id is None: | ||
# Invalid insertion event without next chunk ID | ||
return | ||
|
||
# Keep track of the insertion event and the chunk ID | ||
self.db_pool.simple_insert_txn( | ||
txn, | ||
table="insertion_events", | ||
values={ | ||
"insertion_event_id": event.event_id, | ||
"room_id": event.room_id, | ||
"next_chunk_id": next_chunk_id, | ||
}, | ||
) | ||
|
||
# Insert an edge for every prev_event connection | ||
for prev_event_id in event.prev_events: | ||
self.db_pool.simple_insert_txn( | ||
txn, | ||
table="insertion_event_edges", | ||
values={ | ||
"insertion_event_id": event.event_id, | ||
"room_id": event.room_id, | ||
"insertion_prev_event_id": prev_event_id, | ||
}, | ||
) | ||
|
||
def _handle_chunk_id(self, txn: LoggingTransaction, event: EventBase): | ||
"""Handles inserting the chunk connections between the event at the | ||
start of a chunk and an insertion event | ||
|
||
Args: | ||
txn: The database transaction object | ||
event: The event to process | ||
""" | ||
|
||
chunk_id = event.content.get(EventContentFields.MSC2716_CHUNK_ID) | ||
if chunk_id is None: | ||
# No chunk connection to persist | ||
return | ||
|
||
logger.debug("_handle_chunk_id %s %s", chunk_id, event) | ||
|
||
# Keep track of the insertion event and the chunk ID | ||
self.db_pool.simple_insert_txn( | ||
txn, | ||
table="chunk_edges", | ||
values={ | ||
"event_id": event.event_id, | ||
"room_id": event.room_id, | ||
"chunk_id": chunk_id, | ||
}, | ||
) | ||
|
||
def _handle_redaction(self, txn, redacted_event_id): | ||
"""Handles receiving a redaction and checking whether we need to remove | ||
any redacted relations from the database. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright 2021 The Matrix.org Foundation C.I.C | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
-- Add a table that keeps track of "insertion" events back in the history | ||
-- when we get a "marker" event over the "live" timeline. When navigating the DAG | ||
-- and we hit an event which matches `insertion_prev_event_id`, it should backfill | ||
-- the "insertion" event and start navigating from there. | ||
|
||
CREATE TABLE IF NOT EXISTS insertion_events( | ||
insertion_event_id TEXT NOT NULL, | ||
room_id TEXT NOT NULL, | ||
next_chunk_id TEXT NOT NULL, | ||
UNIQUE (insertion_event_id, room_id, next_chunk_id) | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
|
||
CREATE INDEX IF NOT EXISTS insertion_events_insertion_room_id ON insertion_events(room_id); | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CREATE INDEX IF NOT EXISTS insertion_events_insertion_event_id ON insertion_events(insertion_event_id); | ||
CREATE INDEX IF NOT EXISTS insertion_events_next_chunk_id ON insertion_events(next_chunk_id); | ||
|
||
CREATE TABLE IF NOT EXISTS insertion_event_edges( | ||
insertion_event_id TEXT NOT NULL, | ||
room_id TEXT NOT NULL, | ||
insertion_prev_event_id TEXT NOT NULL, | ||
UNIQUE (insertion_event_id, room_id, insertion_prev_event_id) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS insertion_event_edges_insertion_room_id ON insertion_event_edges(room_id); | ||
CREATE INDEX IF NOT EXISTS insertion_event_edges_insertion_event_id ON insertion_event_edges(insertion_event_id); | ||
CREATE INDEX IF NOT EXISTS insertion_event_edges_insertion_prev_event_id ON insertion_event_edges(insertion_prev_event_id); | ||
|
||
CREATE TABLE IF NOT EXISTS chunk_edges( | ||
event_id TEXT NOT NULL, | ||
room_id TEXT NOT NULL, | ||
chunk_id TEXT NOT NULL, | ||
UNIQUE (event_id, room_id) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS chunk_edges_chunk_id ON chunk_edges(chunk_id); | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we will use this 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to backfilling the insertion event in #10420