-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
User V2 API endpoint #3855
User V2 API endpoint #3855
Conversation
Sentry issue: POSTHOG-2KR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comments but lgtm!
from posthog.test.base import APIBaseTest | ||
|
||
|
||
class TestUser(APIBaseTest): | ||
class TestUserAPI(APIBaseTest): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could move this in separate file to keep files smaller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I actually think this is the class that makes sense keeping here. The other one is just a legacy class to be kept around until we remove the old endpoint.
Thanks for the review @EDsCODE! Would you mind taking another quick look? I've fixed merged conflicts, address your feedback, and some minor tweaks that came up while updating the frontend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, just got some questions regarding routing
Ready for one final look @Twixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some picking of nits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Changes
This PR introduces a brand-new
/api/users/@me/
endpoint. Instead of a full refactor, we introduce the new endpoint while keeping support for the old one for a little while. While we've known for a while this refactor is needed, this is motivated because now it has become a blocker for some teams that have a ton of events and/or event properties (see Slack thread).This PR is already on the larger end of things, as such, I've decided to split this whole refactor, and this particular PR only includes backend changes.
Please don't be scared by the number of file changes or lines. Most lines are tests and the large number of file changes is mostly due to a simple name refactoring of the
UserSerializer
(see below).Detailed changes
/api/users/@me/
endpoint is now built with DRF serializers and views. Among other things we pay special attention to the nested properties included (to reduce them to the minimum). A random sample in production shows a 50x+ reduction in payload size (while this data is still loaded in the frontend, it is no longer blocking to render the app).Team
object] (e.g.team.event_names
,team.event_properties
,team.event_properties_numerical
,team.event_names_with_usage
).current_password
).Team
orOrganization
the respective endpoints need to be used.is_debug
,email_service_available
,is_event_property_usage_enabled
,posthog_version
).$identify
to update the user on every API hit). We also introduce auser updated
backend event.uuid
property (UUIDT
) to theUser
model to start using as key in API requests.UserSerializer
is refactored toUserBasicSerializer
to properly reflect the goal and composition of this serializer. This serializer is now used for any nested properties (e.g. used forcreated_by
in multiple endpoints).last_name
attribute fromUser
model (part of Django's baseAbstractUser
).New API response (GET
/api/users/@me/
)Additional context
/api/user/
&/_preflight
endpoints to be loaded to be able to display the app, instead of requiring this plus,/api/projects/@current/
,/api/organizations/@current/
plus the billing information. These two required endpoints are significantly lighter and faster than they were before. The rest of the info will be loaded without blocking the entire page render. Relevant local components will display a local loading state.Checklist