Skip to content

Commit

Permalink
Prefetch type in the intersect calls.
Browse files Browse the repository at this point in the history
This reduces the queries used.
  • Loading branch information
dracos committed Jun 4, 2024
1 parent 5396ef5 commit 8835262
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mapit/views/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.translation import gettext as _
from django.contrib.gis.geos import Point
from django.contrib.gis.db.models import Collect
from django.db.models import Q
from django.db.models import Q, prefetch_related_objects
from django.db.models.query import QuerySet
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import resolve, reverse, NoReverseMatch
Expand Down Expand Up @@ -207,6 +207,9 @@ def area_intersect(query_type, title, request, area_id, format):
except InternalError:
raise ViewException(format, _('There was an internal error performing that query.'), 500)

# Each object will need type which hasn't been fetched by the RawQuerySet
prefetch_related_objects(areas, 'type')

title = title % ('<a href="%sarea/%d.html">%s</a>' % (reverse('mapit_index'), area.id, area.name))
return output_areas(request, title, format, areas, norobots=True)

Expand Down

0 comments on commit 8835262

Please sign in to comment.