From: Radek Czajka Date: Wed, 19 Sep 2012 12:27:24 +0000 (+0200) Subject: Cache book lists X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/24b135ddf6bcd87ec53d1a98f653d2abcdd22fa5?ds=inline Cache book lists --- diff --git a/apps/catalogue/models/listeners.py b/apps/catalogue/models/listeners.py index 9e9fcabff..7e034a1c6 100644 --- a/apps/catalogue/models/listeners.py +++ b/apps/catalogue/models/listeners.py @@ -3,13 +3,17 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.conf import settings +from django.core.cache import get_cache from django.db.models.signals import post_save, pre_delete, post_delete import django.dispatch -from catalogue.models import Tag, BookMedia, Book, Fragment +from catalogue.models import Tag, BookMedia, Book, Fragment, Collection from catalogue import tasks from newtagging.models import tags_updated +permanent_cache = get_cache('permanent') + + def _tags_updated_handler(sender, affected_tags, **kwargs): # reset tag global counter # we want Tag.changed_at updated for API to know the tag was touched @@ -40,9 +44,17 @@ def _post_save_handler(sender, instance, **kwargs): """ refresh all the short_html stuff on BookMedia update """ if sender == BookMedia: instance.book.save() + elif sender == Collection: + permanent_cache.delete('catalogue.collection:%s' % instance.slug) post_save.connect(_post_save_handler) +def post_publish(sender, **kwargs): + permanent_cache.delete_many(['catalogue.book_list', + 'catalogue.audiobook_list', 'catalogue.daisy_list']) +Book.published.connect(post_publish) + + if not settings.NO_SEARCH_INDEX: @django.dispatch.receiver(post_delete, sender=Book) def _remove_book_from_index_handler(sender, instance, **kwargs): diff --git a/apps/catalogue/templates/catalogue/audiobook_list.html b/apps/catalogue/templates/catalogue/audiobook_list.html index 427f89934..c74f78c74 100644 --- a/apps/catalogue/templates/catalogue/audiobook_list.html +++ b/apps/catalogue/templates/catalogue/audiobook_list.html @@ -20,17 +20,3 @@ Możecie z niej korzystaÄ bezpÅatnie i bez ograniczeÅ. Audiobooki nagrywajÄ znani aktorzy, wÅród nich Danuta Stenka i Jan Peszek.{% endblocktrans %}