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

Commit d2e2aa7

Browse files
committed
Make historical messages available to federated servers
Part of MSC2716: matrix-org/matrix-spec-proposals#2716 Follow-up to #9247
1 parent 33701dc commit d2e2aa7

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

synapse/handlers/federation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ async def maybe_backfill(
10521052
with (await self._room_backfill.queue(room_id)):
10531053
return await self._maybe_backfill_inner(room_id, current_depth, limit)
10541054

1055+
# Todo
10551056
async def _maybe_backfill_inner(
10561057
self, room_id: str, current_depth: int, limit: int
10571058
) -> bool:

synapse/storage/databases/main/event_federation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,8 @@ def get_oldest_events_with_depth_in_room_txn(self, txn, room_id):
663663
" ON g.event_id = e.event_id"
664664
" INNER JOIN event_backward_extremities as b"
665665
" ON g.prev_event_id = b.event_id"
666+
" INNER JOIN insertion_event_extremeties as i"
667+
" ON g.event_id = i.insertion_prev_event_id"
666668
" WHERE b.room_id = ? AND g.is_state is ?"
667669
" GROUP BY b.event_id"
668670
)

synapse/storage/databases/main/events.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,8 @@ def _update_metadata_tables_txn(
15041504

15051505
self._handle_event_relations(txn, event)
15061506

1507+
self._handle_marker_event(txn, event)
1508+
15071509
# Store the labels for this event.
15081510
labels = event.content.get(EventContentFields.LABELS)
15091511
if labels:
@@ -1756,6 +1758,39 @@ def _handle_event_relations(self, txn, event):
17561758
if rel_type == RelationTypes.REPLACE:
17571759
txn.call_after(self.store.get_applicable_edit.invalidate, (parent_id,))
17581760

1761+
def _handle_marker_event(self, txn, event):
1762+
"""Handles inserting insertion extremeties during peristence of marker events
1763+
1764+
Args:
1765+
txn
1766+
event (EventBase)
1767+
"""
1768+
1769+
if event.type != EventTypes.MSC2716_MARKER:
1770+
# Not a marker event
1771+
return
1772+
1773+
insertion_event_id = event.content.get(
1774+
EventContentFields.MSC2716_MARKER_INSERTION
1775+
)
1776+
insertion_prev_event_ids = event.content.get(
1777+
EventContentFields.MSC2716_MARKER_INSERTION_PREV_EVENTS
1778+
)
1779+
if not insertion_event_id or not insertion_prev_event_ids:
1780+
# Invalid marker event
1781+
return
1782+
1783+
for prev_event_id in insertion_prev_event_ids:
1784+
self.db_pool.simple_insert_txn(
1785+
txn,
1786+
table="insertion_event_extremeties",
1787+
values={
1788+
"insertion_event_id": insertion_event_id,
1789+
"room_id": event.room_id,
1790+
"insertion_prev_event_id": prev_event_id,
1791+
},
1792+
)
1793+
17591794
def _handle_redaction(self, txn, redacted_event_id):
17601795
"""Handles receiving a redaction and checking whether we need to remove
17611796
any redacted relations from the database.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright 2021 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+
-- Add a table that keeps track of "insertion" events back in the history
17+
-- when we get a "marker" event over the "live" timeline. When navigating the DAG
18+
-- and we hit an event which matches `insertion_prev_event_id`, it should backfill
19+
-- the "insertion" event and start navigating from there.
20+
21+
22+
CREATE TABLE IF NOT EXISTS insertion_event_extremeties(
23+
insertion_event_id TEXT NOT NULL,
24+
room_id TEXT NOT NULL,
25+
insertion_prev_event_id TEXT NOT NULL,
26+
UNIQUE (insertion_event_id, room_id, room_id, insertion_prev_event_id)
27+
);
28+
29+
CREATE INDEX IF NOT EXISTS insertion_event_extremeties_insertion_room_id ON insertion_event_extremeties(room_id);
30+
CREATE INDEX IF NOT EXISTS insertion_event_extremeties_insertion_event_id ON insertion_event_extremeties(insertion_event_id);
31+
CREATE INDEX IF NOT EXISTS insertion_event_extremeties_insertion_prev_event_id ON insertion_event_extremeties(insertion_prev_event_id);
32+
33+
CREATE TABLE IF NOT EXISTS chunk_connections(
34+
event_id TEXT NOT NULL,
35+
room_id TEXT NOT NULL,
36+
chunk_id TEXT NOT NULL,
37+
UNIQUE (event_id, room_id)
38+
);
39+
40+
CREATE INDEX IF NOT EXISTS chunk_connections_insertion_chunk_id ON chunk_connections(chunk_id);

0 commit comments

Comments
 (0)