Skip to content

Commit

Permalink
feat(fiestarequests): unify prefetching for both submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Sep 15, 2024
1 parent 56a5a17 commit 4e7437e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion fiesta/apps/buddy_system/views/matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class MyBuddies(EnsureLocalUserViewMixin, ListView):

def get_queryset(self):
return (
self.request.user.buddy_system_request_matches.prefetch_related("request__issuer__emailaddress_set")
self.request.user.buddy_system_request_matches.prefetch_related(
"request__issuer__emailaddress_set",
)
.select_related(
"request__issuer__profile__user",
"request__issuer__profile__university",
Expand Down
7 changes: 6 additions & 1 deletion fiesta/apps/buddy_system/views/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ def get_permission_denied_message(self):

def get_queryset(self):
return self.configuration.matching_policy_instance.limit_requests(
qs=BuddyRequest.objects.get_queryset(),
qs=BuddyRequest.objects.get_queryset().select_related(
# select all potentially necessary fields in the template afterward
"issuer__profile__user",
"issuer__profile__university",
"issuer__profile__faculty",
),
membership=self.request.membership,
)

Expand Down
8 changes: 6 additions & 2 deletions fiesta/apps/pickup_system/views/matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ class MyPickups(EnsureLocalUserViewMixin, ListView):

def get_queryset(self):
return (
self.request.user.pickup_system_request_matches.prefetch_related("request__issuer__profile")
.select_related("request", "matcher")
self.request.user.pickup_system_request_matches.prefetch_related("request__issuer__emailaddress_set")
.select_related(
"request__issuer__profile__user",
"request__issuer__profile__university",
"request__issuer__profile__faculty",
)
.filter(
request__state=BaseRequestProtocol.State.MATCHED,
)
Expand Down
4 changes: 3 additions & 1 deletion fiesta/apps/pickup_system/views/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class MatchingRequestsView(

def get_queryset(self):
return self.request.in_space_of_section.pickup_system_requests.select_related(
"issuer__profile__user", "issuer__profile__university", "issuer__profile__faculty"
"issuer__profile__user",
"issuer__profile__university",
"issuer__profile__faculty",
).filter(
state=PickupRequest.State.CREATED,
)
Expand Down

0 comments on commit 4e7437e

Please sign in to comment.