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 4c1d5a2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions geotrek/api/v2/views/outdoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def get_queryset(self):
.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))),
'parent') \
.order_by('name') # Required for reliable pagination


Expand Down Expand Up @@ -94,5 +95,8 @@ def get_queryset(self):
return outdoor_models.Course.objects \
.annotate(geom_transformed=Transform(F('geom'), settings.API_SRID)) \
.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') \
.order_by('name') # Required for reliable pagination

0 comments on commit 4c1d5a2

Please sign in to comment.