dont query for empty list
This commit is contained in:
parent
3a8429b9ac
commit
98bd2f6cf3
1 changed files with 15 additions and 30 deletions
|
@ -107,33 +107,16 @@ 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'))
|
||||
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
|
||||
return self.in_ids(ids, exclude)
|
||||
elif k == 'id':
|
||||
if op == '&':
|
||||
ids = v
|
||||
else:
|
||||
ids = [v]
|
||||
in_op = operators.notin_op if exclude else operators.in_op
|
||||
q = in_op(self._model.id, ids)
|
||||
return q
|
||||
return self.in_ids(ids, exclude)
|
||||
elif k == 'fulltext':
|
||||
ids = find_fulltext(v)
|
||||
if ids:
|
||||
in_op = operators.notin_op if exclude else operators.in_op
|
||||
q = in_op(self._model.id, ids)
|
||||
else:
|
||||
# nothing
|
||||
q = operators.eq(self._model.id, -1)
|
||||
if exclude:
|
||||
q = ~q
|
||||
return q
|
||||
return self.in_ids(ids, exclude)
|
||||
|
||||
elif key_type in ("string", "text"):
|
||||
if isinstance(v, str):
|
||||
|
@ -142,9 +125,7 @@ class Parser(object):
|
|||
if k != '*':
|
||||
q &= (self._find.key == k)
|
||||
ids = self._model.query.join(self._find).filter(q).options(load_only('id'))
|
||||
in_op = operators.notin_op if exclude else operators.in_op
|
||||
q = in_op(self._model.id, ids)
|
||||
return q
|
||||
return self.in_ids(ids, exclude)
|
||||
elif k == 'list':
|
||||
nickname, name = v.split(':', 1)
|
||||
if nickname:
|
||||
|
@ -175,9 +156,7 @@ class Parser(object):
|
|||
)
|
||||
else:
|
||||
ids = l.get_items().options(load_only('id'))
|
||||
in_op = operators.notin_op if exclude else operators.in_op
|
||||
q = in_op(self._model.id, ids)
|
||||
return q
|
||||
return self.in_ids(ids, exclude)
|
||||
elif key_type == 'date':
|
||||
def parse_date(d):
|
||||
while len(d) < 3:
|
||||
|
@ -188,12 +167,18 @@ class Parser(object):
|
|||
vk = getattr(self._sort, k)
|
||||
q = get_operator(op, 'int')(vk, v)
|
||||
ids = self._model.query.join(self._find).filter(q).options(load_only('id'))
|
||||
in_op = operators.notin_op if exclude else operators.in_op
|
||||
q = in_op(self._model.id, ids)
|
||||
return q
|
||||
return self.in_ids(ids, exclude)
|
||||
else: #integer, float, time
|
||||
q = get_operator(op, 'int')(getattr(self._sort, k), v)
|
||||
ids = self._model.query.join(self._find).filter(q).options(load_only('id'))
|
||||
return self.in_ids(ids, exclude)
|
||||
|
||||
def in_ids(self, ids, exclude):
|
||||
if isinstance(ids, list) and 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
|
||||
|
|
Loading…
Reference in a new issue