From 4c6245decfc864cad3c57d17a2f3b3a6acb21e46 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Sat, 1 Dec 2012 15:24:49 +0100 Subject: [PATCH] cache query result of podcast lists only if non-empty --- mygpo/db/couchdb/podcastlist.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mygpo/db/couchdb/podcastlist.py b/mygpo/db/couchdb/podcastlist.py index 50567773..352da6c0 100644 --- a/mygpo/db/couchdb/podcastlist.py +++ b/mygpo/db/couchdb/podcastlist.py @@ -1,12 +1,13 @@ from random import random +from django.core.cache import cache + from mygpo.share.models import PodcastList from mygpo.cache import cache_result from mygpo.db import QueryParameterMissing -@cache_result(timeout=60) def podcastlist_for_user_slug(user_id, slug): if not user_id: @@ -15,12 +16,23 @@ def podcastlist_for_user_slug(user_id, slug): if not slug: raise QueryParameterMissing('slug') + key = 'plist-%s-%s' % (user_id, slug) + + l = cache.get(key) + if l: + return l r = PodcastList.view('podcastlists/by_user_slug', key = [user_id, slug], include_docs = True, ) - return r.first() if r else None + + if r: + l = r.one() + cache.set(key, l, 60) + return l + + return None -- 2.11.4.GIT