remove unknown ids from lists
This commit is contained in:
parent
b12e61c5b4
commit
10e651067c
3 changed files with 17 additions and 3 deletions
|
@ -183,6 +183,15 @@ class Peer(object):
|
||||||
os.unlink(self._infopath)
|
os.unlink(self._infopath)
|
||||||
|
|
||||||
def sync_db(self):
|
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 item.models
|
||||||
import user.models
|
import user.models
|
||||||
c_user_id = item.models.user_items.columns['user_id']
|
c_user_id = item.models.user_items.columns['user_id']
|
||||||
|
|
|
@ -103,6 +103,11 @@ class Parser(object):
|
||||||
vk = getattr(self._sort, k)
|
vk = getattr(self._sort, k)
|
||||||
q = operators.eq(vk, v)
|
q = operators.eq(vk, v)
|
||||||
ids = self._model.query.join(self._sort).filter(q).options(load_only('id'))
|
ids = self._model.query.join(self._sort).filter(q).options(load_only('id'))
|
||||||
|
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
|
in_op = operators.notin_op if exclude else operators.in_op
|
||||||
q = in_op(self._model.id, ids)
|
q = in_op(self._model.id, ids)
|
||||||
return q
|
return q
|
||||||
|
|
|
@ -132,7 +132,7 @@ class User(db.Model):
|
||||||
'type': 'library'
|
'type': 'library'
|
||||||
})
|
})
|
||||||
index = 0
|
index = 0
|
||||||
for name in peer.info['listorder']:
|
for name in peer.info.get('listorder', peer.info.get('lists', []).keys()):
|
||||||
lists.append({
|
lists.append({
|
||||||
'id': '%s:%s' % (self.nickname, name),
|
'id': '%s:%s' % (self.nickname, name),
|
||||||
'user': self.name,
|
'user': self.name,
|
||||||
|
|
Loading…
Reference in a new issue