Skip to content

Commit 07cfe89

Browse files
Merge pull request #2727 from IFRCGo/fix/sentry-6857
Fix SurgeAlert N+1 query issue
2 parents 81986bc + 0e02593 commit 07cfe89

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

notifications/drf_views.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,22 @@ def qs(self):
7171

7272
class SurgeAlertViewset(viewsets.ReadOnlyModelViewSet):
7373
authentication_classes = (TokenAuthentication,)
74-
queryset = SurgeAlert.objects.prefetch_related("molnix_tags", "molnix_tags__groups").select_related("event", "country").all()
74+
queryset = (
75+
SurgeAlert.objects.select_related(
76+
"event",
77+
"event__dtype",
78+
"event__parent_event",
79+
"country",
80+
"country__region",
81+
)
82+
.prefetch_related(
83+
"molnix_tags",
84+
"molnix_tags__groups",
85+
"event__countries",
86+
"event__appeals",
87+
)
88+
.all()
89+
)
7590
filterset_class = SurgeAlertFilter
7691
ordering_fields = ("created_at", "atype", "category", "event", "molnix_status", "opens")
7792
search_fields = (

0 commit comments

Comments
 (0)