mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 08:43:10 +00:00
Use get_indexed_objects to speed up indexing of Images/Documents
Previously, this created a query for every single image and document to get the tags. This was very slow on RCA which has over 15000 images. This commit fixes this by adding a prefetch_related to the QuerySet used for indexing.
This commit is contained in:
parent
9e1bd2d601
commit
b9d3e44ebf
1 changed files with 5 additions and 1 deletions
|
|
@ -21,7 +21,11 @@ class TagSearchable(indexed.Indexed):
|
|||
|
||||
@property
|
||||
def get_tags(self):
|
||||
return ' '.join([tag.name for tag in self.tags.all()])
|
||||
return ' '.join([tag.name for tag in self.prefetched_tags()])
|
||||
|
||||
@classmethod
|
||||
def get_indexed_objects(cls):
|
||||
return super(TagSearchable, cls).get_indexed_objects().prefetch_related('tagged_items__tag')
|
||||
|
||||
@classmethod
|
||||
def search(cls, q, results_per_page=None, page=1, prefetch_tags=False, filters={}):
|
||||
|
|
|
|||
Loading…
Reference in a new issue