Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change use of a sync for obtaining the room history to a room initial sync. #132

Merged
merged 1 commit into from
Sep 17, 2021

Conversation

Gnuxie
Copy link
Contributor

@Gnuxie Gnuxie commented Sep 17, 2021

This is a deprecated API but the call to sync on an account in a large
number of rooms is taking too much time (and can fail), even with strict filtering
limiting the response to a single room.
This code is used to fetch the events to redact from a timeline,
so it is especially problematic.

@Gnuxie Gnuxie requested a review from Yoric September 17, 2021 09:03
@Gnuxie Gnuxie self-assigned this Sep 17, 2021
Copy link
Contributor

@Yoric Yoric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could you reword the commit to something along the lines of:

Use `initialSync` instead of `sync` to fetch room history.

See [github issue]: for the time being, this seems to be the only way to avoid requests that take the server several minutes to complete and timeout.

src/utils.ts Outdated
filter: JSON.stringify(filter),
};
return client.doRequest("GET", "/_matrix/client/r0/sync", qs);
// There is no direct replacement for this and doing a sync here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a function documentation but implementation comment, so this should go inside the function.

Also, it's not clear what you're commenting. Let me suggest:

/*
  Note: `/initialSync` is deprecated. However, there is no replacement for this API for the time being.
  While previous versions of this function used `/sync`, experience shows that it can grow extremely
  slow (4-5 minutes long) when we need to sync many large rooms, which leads to timeouts and
  breakage in Mjolnir, see e.g. [insert issue numbers].
*/

See matrix-org/synapse#10842.
For the time being this seems to be the only way to avoid requests
that take several minutes for synapse to complete and timeout.
@Gnuxie Gnuxie merged commit 7b7130b into main Sep 17, 2021
Gnuxie added a commit that referenced this pull request Oct 14, 2021
Related to #132.
The old code would call `/sync` with this filter. If a token was
provided in the response of `/sync` for earlier messages, it would
then use this same filter to call `/rooms/messages`. However, this
filter does not do anything on that endpoint when we know the id of
the sender, as it requires a RoomEventFilter and there is no warning
or error from synapse about the structure of the filter being wrong.
This was not noticed until after the related PR because `/sync` with
the filter would usually be able to provide a user's
entire history in one room. This is because in most cases a user is banned/redacted
shortly after joining a room.
In the case that `/rooms/messages` was called for more events, the method would
always paginate the timeline up until the limit or the end of the room
history, which is only the expected behavior when matching the sender
with a "glob".
Gnuxie added a commit that referenced this pull request Oct 15, 2021
Related to #132.
The old code would call `/sync` with this filter. If a token was
provided in the response of `/sync` for earlier messages, it would
then use this same filter to call `/rooms/messages`. However, this
filter does not do anything on that endpoint when we know the id of
the sender, as it requires a RoomEventFilter and there is no warning
or error from synapse about the structure of the filter being wrong.
This was not noticed until after the related PR because `/sync` with
the filter would usually be able to provide a user's
entire history in one room. This is because in most cases a user is banned/redacted
shortly after joining a room.
In the case that `/rooms/messages` was called for more events, the method would
always paginate the timeline up until the limit or the end of the room
history, which is only the expected behavior when matching the sender
with a "glob".
Gnuxie added a commit that referenced this pull request Oct 19, 2021
Related to #132.
The old code would call `/sync` with this filter. If a token was
provided in the response of `/sync` for earlier messages, it would
then use this same filter to call `/rooms/messages`. However, this
filter does not do anything on that endpoint when we know the id of
the sender, as it requires a RoomEventFilter and there is no warning
or error from synapse about the structure of the filter being wrong.
This was not noticed until after the related PR because `/sync` with
the filter would usually be able to provide a user's
entire history in one room. This is because in most cases a user is banned/redacted
shortly after joining a room.
In the case that `/rooms/messages` was called for more events, the method would
always paginate the timeline up until the limit or the end of the room
history, which is only the expected behavior when matching the sender
with a "glob".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants