title: Django ListView painfully slow using Haystack
body: <p>How do you speed up a <a href="http://haystacksearch.org/" rel="nofollow">Haystack</a>-search powered (using the Whoosh backend) paginated Django list view?</p>
  
  <p>I had a simple ListView like:</p>
  
  <pre><code>class PersonListView(ListView)
      template_name = 'person-list.html'
      paginated_by = 10
      def get_queryset(self):
          return Person.objects.all()
  </code></pre>
  
  <p>Returning a page with 3000 results runs in about 1 second on my localhost.</p>
  
  <p>I then "plugged in" Haystack to allow full-text searching on names by doing:</p>
  
  <pre><code>class PersonListView(ListView)
      template_name = 'person-list.html'
      paginated_by = 10
      def get_queryset(self):
          #return Person.objects.all()
          return SearchQuerySet().models(models.Person)
  </code></pre>
  
  <p>And I setup the appropriate index and run <code>manage.py rebuild_index</code>:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>However, after this, the same page now takes about 15 seconds to run...</p>
  
  <p>I tried using a <a href="https://github.com/InviteBox/django-live-profiler" rel="nofollow">django profiler</a>, but I don't see much difference in the query times before and after the change, and the longest running query takes only a second, indicating there's some bug on the view side that's causing all the query results to be iterated over.</p>
  
  <p>What's causing Haystack to run horribly slow?</p>