Deduplicating queries when using multiple ModelMultipleChoiceFilter w/ same queryset callable #1572
Unanswered
joeyorlando
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I did a talk on this topic for DjangoCon Europe 2020: Choose, and choose quickly: Optimising ModelChoiceField: https://www.youtube.com/watch?v=e52S1SjuUeM Give that a watch. tl;dr If you set the choices explicitly (from a one-time cached value) you can avoid the repeated query overhead. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hi there 👋
Chiming in with a question from the
grafana/oncall
open source project.We use
django_filter
extensively in the project. I'm noticing some performance issues, which originate from our usage of aFilterSet
subclass we've created. This is resulting in a lot of duplicate SQL queries:Basically the problem is with these fields here where we specify a custom
queryset
callable. Each filter field class inAlertGroupFilter
ends up calling these callables and recreating their ownQuerySet
objects, resulting in tons of duplicate queries. Ideally we’d be able to reuse these querysets somehow.. but I’m currently stumped on how this could be approached.If I modify those callable methods to simply return
<Model>.objects.none()
, the duplicate queries disappear.Beta Was this translation helpful? Give feedback.
All reactions