Skip to content

Commit 56e1640

Browse files
authored
Merge pull request #2106 from matrix-org/matthew/1.0/msc688-msc1227-lazy-loading
incorporate LL review from matthew
2 parents a38af20 + 0506d09 commit 56e1640

File tree

5 files changed

+63
-42
lines changed

5 files changed

+63
-42
lines changed

api/client-server/definitions/room_event_filter.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ allOf:
2525
include_redundant_members:
2626
type: boolean
2727
description: |-
28-
If ``true``, enables redundant membership events. Does not
28+
If ``true``, sends all membership events for all events, even if they have already
29+
been sent to the client. Does not
2930
apply unless ``lazy_load_members`` is ``true``. See
3031
`Lazy-loading room members <#lazy-loading-room-members>`_
3132
for more information. Defaults to ``false``.

api/client-server/message_pagination.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ paths:
115115
type: array
116116
description: |-
117117
A list of state events relevant to showing the ``chunk``. For example, if
118-
``lazy_load_members`` is enabled in the filter then this will contain any
119-
the membership events for the the senders of events in the ``chunk``. Servers should be careful to not exclude
120-
membership events which are older than ones already sent to the client.
121-
Likewise, clients should be cautious and avoid using older membership
122-
events as the current membership event when paginating backwards.
118+
``lazy_load_members`` is enabled in the filter then this may contain
119+
the membership events for the senders of events in the ``chunk``.
123120
124-
Unless ``include_redundant_members`` is ``true``, the server should remove
125-
membership events which would have already been sent to clients in prior calls
126-
to lazy-loading aware endpoints with the same filter.
121+
Unless ``include_redundant_members`` is ``true``, the server
122+
may remove membership events which would have already been
123+
sent to the client in prior calls to this endpoint, assuming
124+
the membership of those members has not changed.
127125
items:
128126
type: object
129127
title: RoomStateEvent

api/client-server/sync.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ paths:
3939
for more information. Lazy-loading members is only supported on a ``StateFilter``
4040
for this endpoint. When lazy-loading is enabled, servers MUST include the
4141
syncing user's own membership event when they join a room, or when the
42-
full state of rooms is requested. The user's own membership event is eligible
42+
full state of rooms is requested, to aid discovering the user's avatar &
43+
displayname.
44+
45+
Like other members, the user's own membership event is eligible
4346
for being considered redundant by the server. When a sync is ``limited``,
44-
the server MUST return membership events for events in the gap (between ``since`` and the start of the returned timeline),
45-
regardless as to whether
46-
or not they are redundant. ``include_redundant_members`` is ignored for limited
47-
syncs.
47+
the server MUST return membership events for events in the gap
48+
(between ``since`` and the start of the returned timeline), regardless
49+
as to whether or not they are redundant. This ensures that joins/leaves
50+
and profile changes which occur during the gap are not lost.
4851
operationId: sync
4952
security:
5053
- accessToken: []
@@ -149,9 +152,9 @@ paths:
149152
type: array
150153
description: |-
151154
The users which can be used to generate a room name
152-
if the room does not have one. Required if the room
153-
does not have a ``m.room.name`` or ``m.room.canonical_alias``
154-
state event with non-empty content.
155+
if the room does not have one. Required if the room's
156+
``m.room.name`` or ``m.room.canonical_alias`` state events
157+
are unset or empty.
155158
156159
This should be the first 5 members of the room, ordered
157160
by stream ordering, which are joined or invited. The

specification/client_server_api.rst

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,32 +1273,51 @@ Lazy-loading room members
12731273

12741274
Membership events often take significant resources for clients to track. In an
12751275
effort to reduce the number of resources used, clients can enable "lazy-loading"
1276-
for room members. By doing this, servers will only ever send membership events
1276+
for room members. By doing this, servers will attempt to only send membership events
12771277
which are relevant to the client.
12781278

1279-
In terms of filters, this means enabling ``lazy_load_members`` on a ``RoomEventFilter``
1280-
(or a ``StateFilter`` in the case of ``/sync`` only). When enabled, lazy-loading
1281-
aware endpoints (see below) will only include membership events for the ``sender``
1282-
of events being included in the response. For example, if a client makes a ``/sync``
1283-
request with lazy-loading enabled, the server will only return membership events
1284-
for the ``sender`` of events in the timeline, not all members of a room.
1285-
1286-
Repeated calls to lazy-loading aware endpoints will result in redundant membership
1287-
events being excluded by default. Clients often track which membership events they
1288-
already have, therefore making the extra information not as useful to the client.
1289-
Clients can always request redundant membership events by setting ``include_redundant_members``
1290-
to true in the filter.
1291-
1292-
Servers should be cautious about which events they consider redundant. Membership
1293-
events can change over time, and should be included as relevant to maintain the
1294-
historical record. Likewise, clients should be cautious about treating an older event
1295-
as the current membership event for a user.
1296-
1297-
.. Note::
1298-
Repeated calls using the same filter to *any* lazy-loading aware endpoint may
1299-
result in redundant membership events being excluded from future calls. For example, a
1300-
request to ``/sync`` followed by a request to ``/messages`` may result in a
1301-
future call to ``/sync`` excluding membership events returned by the ``/messages`` call.
1279+
It is important to understand that lazy-loading is not intended to be a
1280+
perfect optimisation, and that it may not be practical for the server to
1281+
calculate precisely which membership events are relevant to the client. As a
1282+
result, it is valid for the server to send redundant membership events to the
1283+
client to ease implementation, although such redundancy should be minimised
1284+
where possible to conserve bandwidth.
1285+
1286+
In terms of filters, lazy-loading is enabled by enabling ``lazy_load_members``
1287+
on a ``RoomEventFilter`` (or a ``StateFilter`` in the case of ``/sync`` only).
1288+
When enabled, lazy-loading aware endpoints (see below) will only include
1289+
membership events for the ``sender`` of events being included in the response.
1290+
For example, if a client makes a ``/sync`` request with lazy-loading enabled,
1291+
the server will only return membership events for the ``sender`` of events in
1292+
the timeline, not all members of a room.
1293+
1294+
When processing a sequence of events (e.g. by looping on ``/sync`` or
1295+
paginating ``/messages``), it is common for blocks of events in the sequence
1296+
to share a similar set of senders. Rather than responses in the sequence
1297+
sending duplicate membership events for these senders to the client, the
1298+
server MAY assume that clients will remember membership events they have
1299+
already been sent, and choose to skip sending membership events for members
1300+
whose membership has not changed. These are called 'redundant membership
1301+
events'. Clients may request that redundant membership events are always
1302+
included in responses by setting ``include_redundant_members`` to true in the
1303+
filter.
1304+
1305+
The expected pattern for using lazy-loading is currently:
1306+
1307+
* Client performs an initial /sync with lazy-loading enabled, and receives
1308+
only the membership events which relate to the senders of the events it
1309+
receives.
1310+
* Clients which support display-name tab-completion or other operations which
1311+
require rapid access to all members in a room should call /members for the
1312+
currently selected room, with an ``?at`` parameter set to the /sync
1313+
response's from token. The member list for the room is then maintained by
1314+
the state in subsequent incremental /sync responses.
1315+
* Clients which do not support tab-completion may instead pull in profiles for
1316+
arbitrary users (e.g. read receipts, typing notifications) on demand by
1317+
querying the room state or ``/profile``.
1318+
1319+
.. TODO-spec
1320+
This implies that GET /state should also take an ``?at`` param
13021321
13031322
The current endpoints which support lazy-loading room members are:
13041323

specification/modules/instant_messaging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ choose a name:
287287
on the members of the room. Clients should consider `m.room.member`_ events
288288
for users other than the logged-in user, as defined below.
289289

290-
i. If the ``m.heroes`` for the room are greater or equal to
290+
i. If the number of ``m.heroes`` for the room are greater or equal to
291291
``m.joined_member_count + m.invited_member_count - 1``, then use the
292292
membership events for the heroes to calculate display names for the
293293
users (`disambiguating them if required`_) and concatenating them. For

0 commit comments

Comments
 (0)