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

perf: instance cache and select-related for license serialization #599

Closed
wants to merge 1 commit into from

Conversation

iloveagent57
Copy link
Contributor

Description

For large numbers of licenses (> 1000), this change gets us from 100s of SQL queries down to around 10 for each page of admin-license-list results.

  1. Select/prefetch related plans, customer agreements, and renewals in the base queryset of the viewset.
  2. add @cached_property to net_days_until_expiration on the agreement model.
  3. ...but, (2) alone is not enough, because the license serializer is going to instantiate a new instance of a CustomerAgreement per license (but because of (1), it doesn't go to the DB to hydrate it). So we need to roll our own instance cache of MinimalCustomerAgreementSerializer.net_days_until_expiration.
  4. For good measure, throw an instance cache onto the viewset's _get_subscription_plan() - this eliminated 4 duplicate queries.

Testing considerations

  • Include instructions for any required manual tests, and any manual testing that has
    already been performed.
  • Include unit and a11y tests as appropriate
  • Consider performance issues.
  • Check that Database migrations are backwards-compatible

Post-review

Squash commits into discrete sets of changes

@@ -118,6 +119,19 @@ class Meta:
'net_days_until_expiration',
]

def get_net_days_until_expiration(self, obj):
Copy link
Contributor

@pwnage101 pwnage101 Feb 21, 2024

Choose a reason for hiding this comment

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

Does this class-var-based memoization approach work even if many=True is passed to this serializer? I'm not suggesting we actually use many=True anywhere currently, but it does feel like one of those hidden time bombs if it doesn't work.

Copy link
Contributor

@pwnage101 pwnage101 left a comment

Choose a reason for hiding this comment

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

Just one question, but the rest LGTM!

@iloveagent57
Copy link
Contributor Author

closing for now, trying new approach to the nested serialization

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.

2 participants