Skip to content

Commit ba30a74

Browse files
committed
Splat "pad" fix from #18873
1 parent 3116bc9 commit ba30a74

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

synapse/handlers/federation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ async def _maybe_backfill_inner(
253253
_BackfillPoint(event_id, depth, _BackfillPointType.BACKWARDS_EXTREMITY)
254254
for event_id, depth in await self.store.get_backfill_points_in_room(
255255
room_id=room_id,
256-
current_depth=current_depth,
256+
# Per the docstring, it's best to pad the `current_depth` by the
257+
# number of messages you plan to backfill from these points.
258+
current_depth=current_depth + limit,
257259
# We only need to end up with 5 extremities combined with the
258260
# insertion event extremities to make the `/backfill` request
259261
# but fetch an order of magnitude more to make sure there is

synapse/storage/databases/main/event_federation.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,30 @@ async def get_backfill_points_in_room(
12101210
equal to the `current_depth`. Sorted by depth, highest to lowest (descending)
12111211
so the closest events to the `current_depth` are first in the list.
12121212
1213+
Note: We can only do approximate depth comparisons. Backwards extremeties are
1214+
the oldest events we know of in the room but we only know of them because some
1215+
other event referenced them by prev_event and aren't persisted in our database
1216+
yet (meaning we don't know their depth specifically). So we need to look for the
1217+
approximate depth from the events connected to the current backwards
1218+
extremeties.
1219+
1220+
It's best to pad the `current_depth` by the number of messages you plan to
1221+
backfill from these points.
1222+
1223+
Example:
1224+
1225+
- Your pagination token represents a scroll position at `depth` of `100`.
1226+
- We have a backfill point at an approximate depth of `125`
1227+
- You plan to backfill `50` events from that backfill point.
1228+
1229+
When we pad our `current_depth`, `100` + `50` = `150`, we pick up the backfill
1230+
point at `125` (because <= `150`, our `current_depth`), backfill `50` events to
1231+
a depth of `75` in the timeline (exposing new events that we can return `100` ->
1232+
`75`).
1233+
1234+
When we don't pad our `current_depth`, `100` is lower than any of the backfill
1235+
points so we don't pick any and miss out on backfilling any events.
1236+
12131237
We ignore extremities that are newer than the user's current scroll position
12141238
(ie, those with depth greater than `current_depth`) as:
12151239
1. we don't really care about getting events that have happened
@@ -1221,7 +1245,7 @@ async def get_backfill_points_in_room(
12211245
12221246
Args:
12231247
room_id: Room where we want to find the oldest events
1224-
current_depth: The depth at the user's current scrollback position
1248+
current_depth: The depth at the user's current scrollback position (see notes above).
12251249
limit: The max number of backfill points to return
12261250
12271251
Returns:

0 commit comments

Comments
 (0)