Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Add a bulk user info endpoint and deprecate the old one #46

Merged
merged 15 commits into from
Jun 19, 2020

Conversation

anoadragon453
Copy link
Member

The current /user/<user_id>/info API was useful in that it could be used by any user to lookup whether another user was deactivate or expired. However, it was impractical as it only allowed for a single lookup at once. Clients trying to use this API were met with speed issues as they tried to query this information for all users in a room.

This PR adds an equivalent CS and Federation API that takes a list of user IDs, and returning a mapping from user ID to info dictionary.

Note that the federation in this PR was a bit trickier than in the original #12 as we can no longer use a federation query, as those don't allow for JSON bodies - which we require to pass a list of user IDs. Instead we do the whole thing of adding a method to transport/client and transport/server.

This PR also adds unittests. The earlier PR used Sytest, presumably for testing across federation, but as this is Synapse-specific that felt a little gross. Unit tests for the deprecated endpoint have not been added.

Best to be reviewed commit-by-commit.

@anoadragon453 anoadragon453 requested a review from a team June 17, 2020 10:21
We can't just use a federation query here as we need to send a JSON body of
information. This makes things slightly more complex, but it basically boils
down to creating server and client methods.

The server method had some slight annoyance in that you're supposed to do all
the logic in FederationServer, however the logic already exists in the
data_store. You can only access the data_store from the handler, so... cue
relatively useless method in FederationServer.
And deprecate the single-user one. We also update the old one to
use the new store method.
@babolivier babolivier self-requested a review June 17, 2020 13:28
synapse/federation/federation_server.py Outdated Show resolved Hide resolved
synapse/storage/data_stores/main/registration.py Outdated Show resolved Hide resolved
synapse/federation/transport/server.py Outdated Show resolved Hide resolved
synapse/rest/client/v2_alpha/user_directory.py Outdated Show resolved Hide resolved
Returns a dictionary of user_id to info dictionary. Supports remote users
"""

PATTERNS = client_patterns("/user/info$")
Copy link
Contributor

Choose a reason for hiding this comment

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

More of a nitpick, but we probably want to explicitly not serve this endpoint on anything else than /unstable (releases=(0,)) given it's not spec'd. This also applies to the non-bulk one (except if Tchap already relies on it being served on /r0 in which case ugh fine I guess).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I definitely agree. I've switched the new endpoint to /unstable.

@giomfo Do you know whether tchap uses /_matrix/client/r0/user/info or _matrix/client/unstable/user/info?

Copy link
Member

Choose a reason for hiding this comment

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

The current implementation on ios and android was using /r0, but that's ok to switch on /unstable the corresponding code is not used in the current published mobile applications.

I just have to check this point on tchap-web side, but we will handle it. You can go for /unstable

Copy link
Member Author

Choose a reason for hiding this comment

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

As the single-user version is being deprecated I'll just leave it as it is for now.

But the bulk version will be /unstable over (POST /_matrix/client/unstable/users/info).

synapse/rest/client/v2_alpha/user_directory.py Outdated Show resolved Hide resolved
synapse/rest/client/v2_alpha/user_directory.py Outdated Show resolved Hide resolved
Copy link
Contributor

@babolivier babolivier left a comment

Choose a reason for hiding this comment

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

lgtm otherwise, though would like to hear from @giomfo on #46 (comment) first (plus my unresolved point wrt type hints)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants