Backfill in the background if we're doing it "just because" (#15710)

Fix https://github.com/matrix-org/synapse/issues/15702
This commit is contained in:
Eric Eastwood 2023-06-09 15:39:49 -05:00 committed by GitHub
parent 373c0c7ff7
commit fcc3ca37e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -0,0 +1 @@
Speed up `/messages` by backfilling in the background when there are no backward extremities where we are directly paginating.

View file

@ -320,14 +320,21 @@ class FederationHandler:
str(len(sorted_backfill_points)), str(len(sorted_backfill_points)),
) )
# If we have no backfill points lower than the `current_depth` then # If we have no backfill points lower than the `current_depth` then either we
# either we can a) bail or b) still attempt to backfill. We opt to try # can a) bail or b) still attempt to backfill. We opt to try backfilling anyway
# backfilling anyway just in case we do get relevant events. # just in case we do get relevant events. This is good for eventual consistency
# sake but we don't need to block the client for something that is just as
# likely not to return anything relevant so we backfill in the background. The
# only way, this could return something relevant is if we discover a new branch
# of history that extends all the way back to where we are currently paginating
# and it's within the 100 events that are returned from `/backfill`.
if not sorted_backfill_points and current_depth != MAX_DEPTH: if not sorted_backfill_points and current_depth != MAX_DEPTH:
logger.debug( logger.debug(
"_maybe_backfill_inner: all backfill points are *after* current depth. Trying again with later backfill points." "_maybe_backfill_inner: all backfill points are *after* current depth. Trying again with later backfill points."
) )
return await self._maybe_backfill_inner( run_as_background_process(
"_maybe_backfill_inner_anyway_with_max_depth",
self._maybe_backfill_inner,
room_id=room_id, room_id=room_id,
# We use `MAX_DEPTH` so that we find all backfill points next # We use `MAX_DEPTH` so that we find all backfill points next
# time (all events are below the `MAX_DEPTH`) # time (all events are below the `MAX_DEPTH`)
@ -338,6 +345,9 @@ class FederationHandler:
# overall otherwise the smaller one will throw off the results. # overall otherwise the smaller one will throw off the results.
processing_start_time=None, processing_start_time=None,
) )
# We return `False` because we're backfilling in the background and there is
# no new events immediately for the caller to know about yet.
return False
# Even after recursing with `MAX_DEPTH`, we didn't find any # Even after recursing with `MAX_DEPTH`, we didn't find any
# backward extremities to backfill from. # backward extremities to backfill from.