add state.cache and cache some stuff

This commit is contained in:
j 2014-05-26 13:41:59 +02:00
commit 56be46d82e
4 changed files with 56 additions and 24 deletions

View file

@ -276,12 +276,17 @@ class List(db.Model):
return self.public_id.encode('utf-8')
def items_count(self):
from item.models import Item
if self._query:
data = self._query
return Parser(Item).find({'query': data}).count()
else:
return len(self.items)
key = 'list:' + self.public_id
value = state.cache.get(key)
if key is None:
from item.models import Item
if self._query:
data = self._query
value = Parser(Item).find({'query': data}).count()
else:
value = len(self.items)
state.cache.set(key, value)
return value
def json(self):
r = {