Skip to content

Commit

Permalink
💫 [IMPR] Add prefetch to optimize APIv2 Outdoor views (refs #3569)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Jan 22, 2024
1 parent 76412f2 commit 7888b93
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions geotrek/api/v2/views/outdoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def get_queryset(self):
activate(self.request.GET.get('language'))
return outdoor_models.Site.objects \
.annotate(geom_transformed=Transform(F('geom'), settings.API_SRID)) \
.select_related('parent', 'practice', 'type') \
.prefetch_related(Prefetch('attachments',
queryset=Attachment.objects.select_related('license', 'filetype', 'filetype__structure')),
Prefetch('view_points',
queryset=HDViewPoint.objects.select_related('content_type', 'license').annotate(geom_transformed=Transform(F('geom'), settings.API_SRID)))) \
queryset=HDViewPoint.objects.select_related('content_type', 'license').annotate(geom_transformed=Transform(F('geom'), settings.API_SRID))),
'information_desks', 'labels', 'managers', 'pois_excluded', 'portal', 'ratings', 'source', 'themes', 'web_links') \
.order_by('name') # Required for reliable pagination


Expand Down Expand Up @@ -93,6 +95,10 @@ def get_queryset(self):
activate(self.request.GET.get('language'))
return outdoor_models.Course.objects \
.annotate(geom_transformed=Transform(F('geom'), settings.API_SRID)) \
.select_related('type') \
.prefetch_related(Prefetch('attachments',
queryset=Attachment.objects.select_related('license', 'filetype', 'filetype__structure'))) \
queryset=Attachment.objects.select_related('license', 'filetype', 'filetype__structure')),
Prefetch('course_children', queryset=outdoor_models.OrderedCourseChild.objects.select_related('parent', 'child')),
Prefetch('course_parents', queryset=outdoor_models.OrderedCourseChild.objects.select_related('parent', 'child')),
'parent_sites', 'pois_excluded', 'ratings') \
.order_by('name') # Required for reliable pagination

0 comments on commit 7888b93

Please sign in to comment.