python - Django ListView painfully slow using Haystack -
how speed haystack-search powered (using whoosh backend) paginated django list view?
i had simple listview like:
class personlistview(listview) template_name = 'person-list.html' paginated_by = 10 def get_queryset(self): return person.objects.all()
returning page 3000 results runs in 1 second on localhost.
i "plugged in" haystack allow full-text searching on names doing:
class personlistview(listview) template_name = 'person-list.html' paginated_by = 10 def get_queryset(self): #return person.objects.all() return searchqueryset().models(models.person)
and setup appropriate index , run manage.py rebuild_index
:
class personindex(indexes.searchindex, indexes.indexable): text = indexes.charfield(document=true, use_template=true) nickname = indexes.charfield() first_name = indexes.charfield() middle_name = indexes.charfield() last_name = indexes.charfield() def get_model(self): return models.person def index_queryset(self, using=none): return self.get_model().objects.all()
however, after this, same page takes 15 seconds run...
i tried using django profiler, don't see difference in query times before , after change, , longest running query takes second, indicating there's bug on view side that's causing query results iterated over.
what's causing haystack run horribly slow?
one reason search being slow is, every search result haystack try corresponding object database. can prevent behaviour using load_all()
on searchqueryset
. haystack try collect results in 1 query. careful when displaying stuff coming related models, cause additional database lookups without additional configuration.
if want avoid database lookups in general , only display data indexed (you can try make sure slowness caused addional database lookups). otherwise if need additional debugging, use debug-toolbar, display database queries , there's additional haystack panel it.
Comments
Post a Comment