-
Notifications
You must be signed in to change notification settings - Fork 2
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
add_representative_country_and_main_mandate is suboptimal #19
Comments
Yeah we can do this, if that causes any additional query (i'm thinking about the list page this could cause N+N*2 queries ^^) tests should tell us ;) |
It will be 2 queries fetching each one row instead of one big query and a loop over it, it may be slower in case there is a very limited amount of mandates but i think it will be a gain in most cases. |
Performance optimization code could be prettier here I agree with that. At least it's pretty explicit what happens here ;) That said, I would be suprised if replacing one query by several does a performance gain, particularely in the case of the list page, ie. with 96 objects displayed in the list, that would cause 193 queries, sounds like database butchering to me :D |
Yeah i didn't took into consideration that the mandates are prefetched anyway so those queries would just add to the total. But 96 queries doesn't look too good either to be honest, and if i had to chose i'd rather make 192 instant queries than 96 big ones ? |
Exactly what I was thinking, either duplicate the logic, and just do the I don't know if duplicating the logic would be such a bad thing here, if @bram any opinion on this ? |
So i was looking for where representative.main_mandate came from and it led me to representatives.views.RepresentativeViewMixin.add_representative_country_and_main_mandate
and i think the same could be done with:
And since it's not so time consuming any more cached properties on the model would be cool ?
The text was updated successfully, but these errors were encountered: