1👍
You say in the question:
I then updated my search view to prefetch relations […]
The code you present, though, does not use QuerySet.prefetch_related
for most of them. Instead, your sample code uses QuerySet.select_related
for most of them; this does not pre-fetch the objects.
The documentation for each of those methods is extensive and can help to decide which is correct for your case.
In particular, the QuerySet.prefetch_related
documentation says:
select_related
works by creating an SQL join and including the fields of the related object in theSELECT
statement. For this reason, select_related gets the related objects in the same database query. However, to avoid the much larger result set that would result from joining across a ‘many’ relationship,select_related
is limited to single-valued relationships – foreign key and one-to-one.
prefetch_related
, on the other hand, does a separate lookup for each relationship, and does the ‘joining’ in Python. This allows it to prefetch many-to-many and many-to-one objects, which cannot be done usingselect_related
, in addition to the foreign key and one-to-one relationships that are supported byselect_related
. It also supports prefetching ofGenericRelation
andGenericForeignKey
, however, it must be restricted to a h*m*geneous set of results. For example, prefetching objects referenced by aGenericForeignKey
is only supported if the query is restricted to oneContentType
.
0👍
Try adding
HAYSTACK_LIMIT_TO_REGISTERED_MODELS = False
to your settings.py. As per the docks,
‘If your search index is never used for anything other than the models registered with Haystack, you can turn this off and get a small to moderate performance boost.’
It knocked 3-4 seconds off for my project
- Append to site <title> in Django template using block.super
- How to separate users (models) by admins and customers on Django
- SAML with Django authentication
- How to get rid of the #_=_ in the facebook redirect of django-social-auth?
- How to build a json REST API in django (without Django REST framework)