remove unused list cache

This commit is contained in:
j 2016-01-10 17:27:45 +05:30
parent ad6afd599e
commit bc593b65fd
3 changed files with 0 additions and 38 deletions

View file

@ -156,7 +156,6 @@ class Changelog(db.Model):
if user not in i.users: if user not in i.users:
i.add_user(user) i.add_user(user)
i.update() i.update()
user.clear_smart_list_cache()
return True return True
def action_edititem(self, user, timestamp, itemid, meta): def action_edititem(self, user, timestamp, itemid, meta):
@ -194,7 +193,6 @@ class Changelog(db.Model):
else: else:
i.update_meta(meta, modified=i.modified) i.update_meta(meta, modified=i.modified)
i.save() i.save()
user.clear_smart_list_cache()
return True return True
def action_removeitem(self, user, timestamp, itemid): def action_removeitem(self, user, timestamp, itemid):
@ -207,8 +205,6 @@ class Changelog(db.Model):
i.update() i.update()
else: else:
i.delete() i.delete()
user.clear_list_cache()
user.clear_smart_list_cache()
return True return True
def action_addlist(self, user, timestamp, name, query=None): def action_addlist(self, user, timestamp, name, query=None):
@ -224,7 +220,6 @@ class Changelog(db.Model):
if 'name' in new: if 'name' in new:
l.name = new['name'] l.name = new['name']
l.save() l.save()
user.clear_list_cache()
return True return True
def action_orderlists(self, user, timestamp, lists): def action_orderlists(self, user, timestamp, lists):
@ -242,7 +237,6 @@ class Changelog(db.Model):
l = List.get(user.id, name) l = List.get(user.id, name)
if l: if l:
l.remove() l.remove()
user.clear_list_cache()
return True return True
def action_addlistitems(self, user, timestamp, name, ids): def action_addlistitems(self, user, timestamp, name, ids):
@ -302,7 +296,6 @@ class Changelog(db.Model):
m = Metadata.get_or_create(key, value) m = Metadata.get_or_create(key, value)
if m.edit(data, False): if m.edit(data, False):
m.update_items() m.update_items()
user.clear_smart_list_cache()
return True return True
def action_resetmeta(self, user, timestamp, key, value): def action_resetmeta(self, user, timestamp, key, value):
@ -310,5 +303,4 @@ class Changelog(db.Model):
m = Metadata.get(key, value) m = Metadata.get(key, value)
if m and m.timestamp < timestamp: if m and m.timestamp < timestamp:
m.reset() m.reset()
user.clear_smart_list_cache()
return True return True

View file

@ -34,7 +34,6 @@ else:
preferences = pdict(os.path.join(config_path, 'preferences.json'), config['user']['preferences']) preferences = pdict(os.path.join(config_path, 'preferences.json'), config['user']['preferences'])
ui = pdict(os.path.join(config_path, 'ui.json'), config['user']['ui']) ui = pdict(os.path.join(config_path, 'ui.json'), config['user']['ui'])
list_cache = pdict(os.path.join(config_path, 'list_cache.json'), {})
server = pdict(os.path.join(config_path, 'server.json')) server = pdict(os.path.join(config_path, 'server.json'))
server_defaults = { server_defaults = {

View file

@ -89,22 +89,6 @@ class User(db.Model):
self.library self.library
return [l.json() for l in self.lists.order_by('index_')] return [l.json() for l in self.lists.order_by('index_')]
def clear_list_cache(self):
if self.id == settings.USER_ID:
prefix = ':'
else:
prefix = self.id + ':'
for key in list(settings.list_cache):
if key.startswith(prefix):
del settings.list_cache[key]
def clear_smart_list_cache(self):
qs = List.query.filter_by(type='smart')
smart_lists = [':%d' % l.id for l in qs]
for key in list(settings.list_cache):
if key in smart_lists:
del settings.list_cache[key]
def update_peering(self, peered, username=None): def update_peering(self, peered, username=None):
was_peering = self.peered was_peering = self.peered
if peered: if peered:
@ -136,7 +120,6 @@ class User(db.Model):
Changelog.query.filter_by(user_id=self.id).delete() Changelog.query.filter_by(user_id=self.id).delete()
if self.id in settings.ui['showFolder']: if self.id in settings.ui['showFolder']:
del settings.ui['showFolder'][self.id] del settings.ui['showFolder'][self.id]
self.clear_list_cache()
self.save() self.save()
if was_peering: if was_peering:
Changelog.record(state.user(), 'removepeer', self.id) Changelog.record(state.user(), 'removepeer', self.id)
@ -263,8 +246,6 @@ class List(db.Model):
state.db.session.commit() state.db.session.commit()
if self.user_id == settings.USER_ID and self.name != '': if self.user_id == settings.USER_ID and self.name != '':
Changelog.record(self.user, 'addlistitems', self.name, items) Changelog.record(self.user, 'addlistitems', self.name, items)
self.user.clear_smart_list_cache()
self.user.clear_list_cache()
def get_items(self): def get_items(self):
from item.models import Item from item.models import Item
@ -284,8 +265,6 @@ class List(db.Model):
state.db.session.commit() state.db.session.commit()
if self.user_id == settings.USER_ID and self.name != '': if self.user_id == settings.USER_ID and self.name != '':
Changelog.record(self.user, 'removelistitems', self.name, items) Changelog.record(self.user, 'removelistitems', self.name, items)
self.user.clear_smart_list_cache()
self.user.clear_list_cache()
def remove(self): def remove(self):
if not self._query: if not self._query:
@ -318,13 +297,6 @@ class List(db.Model):
def items_count(self): def items_count(self):
return self.get_items().count() return self.get_items().count()
key = self.find_id
if key in settings.list_cache:
value = settings.list_cache[key]
else:
value = self.get_items().count()
settings.list_cache[key] = value
return value
def json(self): def json(self):
r = { r = {
@ -332,7 +304,6 @@ class List(db.Model):
'user': self.user.name, 'user': self.user.name,
'name': self.name, 'name': self.name,
'index': self.index_, 'index': self.index_,
# to slow for many smart lists
'items': self.items_count(), 'items': self.items_count(),
'type': self.type 'type': self.type
} }