From: Radek Czajka Date: Wed, 31 Jul 2013 15:01:06 +0000 (+0200) Subject: Tagged view optimization. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/65f855a3c560cdd245b880cf751a945b4f6f5273?ds=sidebyside;hp=-c Tagged view optimization. --- 65f855a3c560cdd245b880cf751a945b4f6f5273 diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index e80b8af73..d69cf2aca 100644 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -75,7 +75,7 @@ class Book(models.Model): self.sort_key = sortify(self.title) - ret = super(Book, self).save(force_insert, force_update) + ret = super(Book, self).save(force_insert, force_update, **kwargs) if reset_short_html: self.reset_short_html() @@ -511,10 +511,11 @@ class Book(models.Model): """ # get relevant books and their tags objects = cls.tagged.with_all(tags) + parents = objects.filter(html_file='').only('slug') # eliminate descendants l_tags = Tag.objects.filter(category='book', - slug__in=[book.book_tag_slug() for book in objects.iterator()]) - descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).iterator()] + slug__in=[book.book_tag_slug() for book in parents.iterator()]) + descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).only('pk').iterator()] if descendants_keys: objects = objects.exclude(pk__in=descendants_keys) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index d69e5428c..e9b1465dd 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -186,7 +186,7 @@ def tagged_object_list(request, tags=''): # get related tags from `tag_counter` and `theme_counter` related_counts = {} tags_pks = [tag.pk for tag in tags] - for book in objects.iterator(): + for book in objects: for tag_pk, value in itertools.chain(book.tag_counter.iteritems(), book.theme_counter.iteritems()): if tag_pk in tags_pks: continue