remove unknown ids from lists

This commit is contained in:
j 2016-02-11 22:22:52 +05:30
parent b12e61c5b4
commit 10e651067c
3 changed files with 17 additions and 3 deletions

View file

@ -183,6 +183,15 @@ class Peer(object):
os.unlink(self._infopath)
def sync_db(self):
ids = set(self.library.keys())
changed = False
for name, l in self.info.get('lists', {}).items():
removed = set(l) - ids
if removed:
self.info['lists'][name] = list(set(l) - removed)
changed = True
if changed:
self.sync_info()
import item.models
import user.models
c_user_id = item.models.user_items.columns['user_id']

View file

@ -103,8 +103,13 @@ class Parser(object):
vk = getattr(self._sort, k)
q = operators.eq(vk, v)
ids = self._model.query.join(self._sort).filter(q).options(load_only('id'))
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
if not ids:
q = operators.eq(self._model.id, '')
if exclude:
q = ~q
else:
in_op = operators.notin_op if exclude else operators.in_op
q = in_op(self._model.id, ids)
return q
elif key_type in ("string", "text"):
if isinstance(v, str):

View file

@ -132,7 +132,7 @@ class User(db.Model):
'type': 'library'
})
index = 0
for name in peer.info['listorder']:
for name in peer.info.get('listorder', peer.info.get('lists', []).keys()):
lists.append({
'id': '%s:%s' % (self.nickname, name),
'user': self.name,