add state.cache and cache some stuff
This commit is contained in:
parent
5b33721c87
commit
56be46d82e
4 changed files with 56 additions and 24 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue