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

ref: Plan query optimizations #1131

Conversation

ajay-sentry
Copy link
Contributor

Purpose/Motivation

Some more plan optimizations for the update_plan helper and when determining if we want to fire the sentry webhook when moving to a sentry plan. Consequently updates the tests.

The update_plan helper change is the main one, mostly just consolidating the 2 queries to a single one and passing the relevant params down that are needed

This should be merged into the remove reference PR before merging that one, but can also be done separately

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Copy link

sentry-io bot commented Feb 5, 2025

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: api/internal/owner/serializers.py

Function Unhandled Issue
update AttributeError: property 'root_organization' of 'Owner' object has no setter /internal/{service}/{owne...
Event Count: 12

Did you find this useful? React with a 👍 or 👎

@@ -404,7 +411,11 @@ def modify_subscription(self, owner, desired_plan):
)

def _modify_subscription_schedule(
self, owner: Owner, subscription, subscription_schedule_id, desired_plan
self,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just some types

@@ -453,20 +464,18 @@ def _modify_subscription_schedule(
metadata=self._get_checkout_session_and_subscription_metadata(owner),
)

def _is_upgrading_seats(self, owner: Owner, desired_plan: dict) -> bool:
def _is_upgrading_seats(self, owner: Owner, quantity: int) -> bool:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

swap this to just quantity


def _is_extending_term(self, owner: Owner, desired_plan: dict) -> bool:
def _is_extending_term(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

swap this to just the two plan references

def _is_similar_plan(self, owner: Owner, desired_plan: dict) -> bool:
def _is_similar_plan(
self,
owner: Owner,
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 one needs all 4 properties, the owner, both plan references, and the quantity

def _get_proration_params(
self, owner: Owner, desired_plan_info: Plan, quantity: int
) -> str:
current_plan_info = Plan.objects.select_related("tier").get(name=owner.plan)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

where we're doing the current_plan_info query, the desired_plan one is one level up (saving us an extra query here)

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.06%. Comparing base (7218333) to head (7425e16).
Report is 1 commits behind head on Ajay/remove-references-to-old-plan-representations.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                                 Coverage Diff                                 @@
##           Ajay/remove-references-to-old-plan-representations    #1131   +/-   ##
===================================================================================
  Coverage                                               96.05%   96.06%           
===================================================================================
  Files                                                     837      837           
  Lines                                                   19768    19765    -3     
===================================================================================
- Hits                                                    18988    18987    -1     
+ Misses                                                    780      778    -2     
Flag Coverage Δ
unit 95.97% <100.00%> (+0.01%) ⬆️
unit-latest-uploader 95.97% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

github-actions bot commented Feb 5, 2025

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@codecov-qa
Copy link

codecov-qa bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.97%. Comparing base (7218333) to head (7425e16).
Report is 1 commits behind head on Ajay/remove-references-to-old-plan-representations.

✅ All tests successful. No failed tests found.

proration_behavior = self._get_proration_params(
owner,
desired_plan_info=desired_plan_info,
quantity=desired_plan["quantity"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: would change this to "desired_quantity"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair point, I'll make the update in the other PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I lied fixed in7425e16

Copy link
Contributor

@adrian-codecov adrian-codecov left a comment

Choose a reason for hiding this comment

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

Lgtm! I'm wondering if there's an easy way to cache these generic values during runtime. Not a huge fan of adding many DB queries per subscription/any time we want plan data that's just going to be static.

I wonder if we could have longterm a redis cache that caches all plan data from the DB for like a day and then we wouldn't be pinging the DB any time we tell it "gimme the basic plan, gimme the pro year plan" etc (this is different than your own plan). And we could make it fancier by invalidating the cache if we see a change in the plan/tier database or something

@ajay-sentry ajay-sentry merged commit 4330f01 into Ajay/remove-references-to-old-plan-representations Feb 5, 2025
15 of 16 checks passed
@ajay-sentry ajay-sentry deleted the Ajay/plan-query-optimizations branch February 5, 2025 22:12
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.

3 participants