Temp: Implement /messages?backfill=true/false
To try out the flow:
- **Default to fast responses with gaps**: As a default, we can always
respond quickly and indicate gaps ([MSC3871]
(https://github.com/matrix-org/matrix-spec-proposals/pull/3871)) for
clients to paginate at their leisure.
- **Fast back-pagination**: Clients back-paginate with
`/messages?dir=b&backfill=false`, and Synapse skips backfilling
entirely, returning only local history with gaps as necessary.
- **Explicit gap filling**: To fill in gaps, clients use
`/messages?dir=b&backfill=true` which works just like today to do a best
effort backfill.
This allows the client to back-paginate the history we already have without
delay. And can fill in the gaps as they see fit.
This is basically a simplified version of [MSC4282]
(https://github.com/matrix-org/matrix-spec-proposals/pull/4282).
This commit is contained in:
@@ -414,12 +414,14 @@ class PaginationHandler:
|
||||
@trace
|
||||
async def get_messages(
|
||||
self,
|
||||
*,
|
||||
requester: Requester,
|
||||
room_id: str,
|
||||
pagin_config: PaginationConfig,
|
||||
as_client_event: bool = True,
|
||||
event_filter: Optional[Filter] = None,
|
||||
use_admin_priviledge: bool = False,
|
||||
backfill: bool = True,
|
||||
) -> JsonDict:
|
||||
"""Get messages in a room.
|
||||
|
||||
@@ -432,6 +434,8 @@ class PaginationHandler:
|
||||
use_admin_priviledge: if `True`, return all events, regardless
|
||||
of whether `user` has access to them. To be used **ONLY**
|
||||
from the admin API.
|
||||
backfill: If false, we skip backfill altogether. When true, we backfill as a
|
||||
best effort.
|
||||
|
||||
Returns:
|
||||
Pagination API results
|
||||
@@ -522,7 +526,7 @@ class PaginationHandler:
|
||||
event_filter=event_filter,
|
||||
)
|
||||
|
||||
if pagin_config.direction == Direction.BACKWARDS:
|
||||
if backfill and pagin_config.direction == Direction.BACKWARDS:
|
||||
# We use a `Set` because there can be multiple events at a given depth
|
||||
# and we only care about looking at the unique continum of depths to
|
||||
# find gaps.
|
||||
|
||||
@@ -811,6 +811,17 @@ class RoomMessageListRestServlet(RestServlet):
|
||||
async def on_GET(
|
||||
self, request: SynapseRequest, room_id: str
|
||||
) -> Tuple[int, JsonDict]:
|
||||
"""
|
||||
Query paremeters:
|
||||
dir
|
||||
from
|
||||
to
|
||||
limit
|
||||
filter
|
||||
backfill: If false, we skip backfill altogether. When true, we backfill as a
|
||||
best effort.
|
||||
"""
|
||||
|
||||
processing_start_time = self.clock.time_msec()
|
||||
# Fire off and hope that we get a result by the end.
|
||||
#
|
||||
@@ -840,12 +851,15 @@ class RoomMessageListRestServlet(RestServlet):
|
||||
):
|
||||
as_client_event = False
|
||||
|
||||
backfill = parse_boolean(request, "backfill", default=True)
|
||||
|
||||
msgs = await self.pagination_handler.get_messages(
|
||||
room_id=room_id,
|
||||
requester=requester,
|
||||
pagin_config=pagination_config,
|
||||
as_client_event=as_client_event,
|
||||
event_filter=event_filter,
|
||||
backfill=backfill,
|
||||
)
|
||||
|
||||
processing_end_time = self.clock.time_msec()
|
||||
|
||||
Reference in New Issue
Block a user