Comments (2)
I led a short investigation into this performance issue. The optimization likely would come from looking more closely at PlanSerializer
, which now initializes the PlanDetailSerializer
. This is done with the many=True
flag, but regardless still calls the Query for each object in the returned list.
@diego-escobedo, I am not seeing 180 db hits. How many plans do you currently have that are being loaded?
For example, if I set up 3 plans (which only have a name
), and then call /app/plans/
:
If I dig a little deeper, I arrive at PlanDetailSerializer.get_versions
being responsible for 39 of these queries (13 for each nth Plan).
def get_versions(self, obj) -> PlanVersionDetailSerializer(many=True):
return PlanVersionDetailSerializer(
obj.versions.all().order_by("version"), many=True
).data
If I remove get_versions, then obv. we have a much more performant request, the time is almost cut in half:
Ideally, this could be annotated and combined into a join with 1 or 2 queries.
Additionally, for every request to /app/plans/
there is another call being made to /app/organizations/
, which unless I am mistaking, should not be necessary, but it is resulting in another 33 additional queries.
Can't solve the issue, but perhaps its enough help to investigate.
If I have some more time I will look into it as well.
from lotus.
Seeing the number of queries here. I have 7 plan versions in mine so its possible its doing even more inefficiently in the get_versions. First step I'm thinking of taking is using the to_attr in the prefetching of the versions so that it gets used explicitly in get_versions. I suspect calling obj.versions.all().order_by("version") refetches everything.
this cuts maybe like 7 queries per plan. Another thing I'm noticing is I'm not prefetching recurring charges, which were separated from being columns of plan versions into their own models.
I'm curious at this point to see how much of the remaining queries are from stuff further down the stack. I prefetch everything we should need in the get_queryset method of the PlanViewSet, but it seems likely most of this ends up not being used. I suspect part of this comes from display_version, which is just one of the versions but gets pulled directly by the PlanDetailSerializer from the model instead of using the already prefetched version.
Next problem seems to be these queries associated with the recurring charges.
Started using the prefetched versions instead of just whatever the plan decided to pull,
Now need to figure out why that single plan also gets pulled, and where these organization queries are coming from.
Turns out they were coming from the TimezoneFieldMixin. It was 1. using db lookups instead of caching (and deleting cached timezones when changed) and 2. checking even when there was no datetimefield in the representation.
getting close! just weird that we have another query lookup after the entrypoint post prefetching.
boom! demolished those queries. Thank you so much for the help @genego-io
from lotus.
Related Issues (20)
- Tags for Customers HOT 1
- Community Integrations HOT 1
- Feat: Quickstart Loading bar in sidebar HOT 1
- Re-enable taxes for generate_balance_adjustment_invoice
- Move Cost Analysis into Custom Viewset HOT 1
- Improve Code Formatting and Copy on Quickstart page HOT 1
- Route to original page after login HOT 3
- difference between lotus and stigg.io ? HOT 3
- Bulk tiers broke plan creation with components HOT 2
- Is this project still active? HOT 4
- Addons description field required on backend HOT 1
- Subscription endpoint 500 HOT 3
- Problem adding a filter to the metric
- Project status HOT 1
- Error creating new customer when address specified
- Docker compose `SVIX_DB_DSN` does not use `POSTGRES_USER`
- Improper documentation of API authentication
- Multiple billable accounts HOT 2
- Inquiry Regarding Switching Dependency from Redpanda to Kafka HOT 2
- Self hosting error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lotus.