Skip to content

fix(hc): Introduce Organization.get_bulk_owner_profiles #68756

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

Merged
merged 9 commits into from
Apr 22, 2024

Conversation

RyanSkonnord
Copy link
Contributor

Support a specialized optimization in getsentry. The purpose is to get a lightweight view of the owners of an arbitrary number of organizations and while making only one RPC.

Support a specialized optimization in getsentry. The purpose is to get a
lightweight view of the owners of an arbitrary number of organizations
and while making only one RPC.
@RyanSkonnord RyanSkonnord requested review from a team as code owners April 11, 2024 23:13
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 11, 2024
@RyanSkonnord
Copy link
Contributor Author

For context, see https://github.com/getsentry/getsentry/pull/13614 and https://github.com/getsentry/getsentry/pull/13622.

See https://github.com/getsentry/getsentry/pull/13623 for the intended usage.

This is a significant amount of code being added for an unfortunately narrow purpose, but ideally it will be the silver bullet we need to solve painfully slow page loads in _admin's customer index view.

) -> dict[int, RpcUserContact]:
owner_id_table = cls._get_bulk_owner_ids(organizations)

contacts = user_service.get_bulk_contact_info(user_ids=list(owner_id_table.values()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This safe to roll out at the same time as the new service method, because nothing is going to hit get_bulk_owner_contacts until https://github.com/getsentry/getsentry/pull/13623 is merged.

Copy link

codecov bot commented Apr 11, 2024

Bundle Report

Bundle size has no change ✅

@RyanSkonnord
Copy link
Contributor Author

Unit tests to be added, btw.

@@ -283,6 +287,10 @@ def get_user_avatar(self, *, user_id: int) -> RpcAvatar | None:

return serialize_user_avatar(avatar=possible_avatar)

def get_bulk_contact_info(self, *, user_ids: list[int]) -> list[RpcUserContact]:
users = User.objects.filter(id__in=user_ids).values_list("id", "name", "email")
return [RpcUserContact(id=id, name=name, email=email) for (id, name, email) in users]
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we have other flows in the application that could benefit from loading less data when needing to show lists of users 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Attempted to generalize this in #68847.

return owner_id_table

@classmethod
def get_bulk_owner_contacts(
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to have a test for this method as it is public interface that getsentry will rely on.

Offer a more performant alternative to UserService.get_many that
provides all attributes that can be provided without fetching from any
related tables.
Rename `ids_only` to more accurately reflect what it does, since
`get_many_profiles` is now using it to fetch more than just IDs but
still wants to avoid selecting any related data.

Make `query_many` no longer private by convention. We now want to call
it directly, so that we can then do a different kind of serialization
than _UserFilterQuery's default. (DatabaseBackedUserSocialAuthService
also was previously calling it directly.)
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.73%. Comparing base (511f07b) to head (ccafde3).
Report is 5 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #68756       +/-   ##
===========================================
- Coverage   91.22%   79.73%   -11.50%     
===========================================
  Files        2848     6444     +3596     
  Lines      176397   286150   +109753     
  Branches    31461    49304    +17843     
===========================================
+ Hits       160910   228148    +67238     
- Misses      15486    57634    +42148     
- Partials        1      368      +367     
Files Coverage Δ
src/sentry/models/organization.py 92.62% <100.00%> (+0.76%) ⬆️

... and 3600 files with indirect coverage changes

@markstory
Copy link
Member

Looks good once #68847 is deployed.

@RyanSkonnord RyanSkonnord changed the title fix(hc): Introduce Organization.get_bulk_owner_contacts fix(hc): Introduce Organization.get_bulk_owner_profiles Apr 17, 2024
@RyanSkonnord
Copy link
Contributor Author

Should now be ready to merge.

@RyanSkonnord RyanSkonnord merged commit 450bf5c into master Apr 22, 2024
49 checks passed
@RyanSkonnord RyanSkonnord deleted the get-bulk-owner-contacts-for-orgs branch April 22, 2024 22:17
MichaelSun48 pushed a commit that referenced this pull request Apr 25, 2024
Support a specialized optimization in getsentry. The purpose is to get a
lightweight view of the owners of an arbitrary number of organizations
and while making only one RPC.
@github-actions github-actions bot locked and limited conversation to collaborators May 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants