forked from edward/owl-map
Avoid making queries with 100s of parameters
This commit is contained in:
parent
bf98eb71dc
commit
2229605672
|
@ -550,18 +550,23 @@ def get_tag_filter(
|
||||||
tags: sqlalchemy.sql.schema.Column, tag_list: list[str]
|
tags: sqlalchemy.sql.schema.Column, tag_list: list[str]
|
||||||
) -> list[sqlalchemy.sql.elements.BooleanClauseList]:
|
) -> list[sqlalchemy.sql.elements.BooleanClauseList]:
|
||||||
tag_filter = []
|
tag_filter = []
|
||||||
|
|
||||||
|
include_prefix = len(tag_list) < 10
|
||||||
|
|
||||||
for tag_or_key in tag_list:
|
for tag_or_key in tag_list:
|
||||||
if tag_or_key.startswith("Key:"):
|
if tag_or_key.startswith("Key:"):
|
||||||
key = tag_or_key[4:]
|
key = tag_or_key[4:]
|
||||||
tag_filter.append(and_(tags.has_key(key), tags[key] != "no"))
|
tag_filter.append(and_(tags.has_key(key), tags[key] != "no"))
|
||||||
for prefix in tag_prefixes:
|
if include_prefix:
|
||||||
tag_filter.append(tags.has_key(f"{prefix}:{key}"))
|
for prefix in tag_prefixes:
|
||||||
|
tag_filter.append(tags.has_key(f"{prefix}:{key}"))
|
||||||
|
|
||||||
if tag_or_key.startswith("Tag:"):
|
if tag_or_key.startswith("Tag:"):
|
||||||
k, _, v = tag_or_key[4:].partition("=")
|
k, _, v = tag_or_key[4:].partition("=")
|
||||||
tag_filter.append(tags[k] == v)
|
tag_filter.append(tags[k] == v)
|
||||||
for prefix in tag_prefixes:
|
if include_prefix:
|
||||||
tag_filter.append(tags[f"{prefix}:{k}"] == v)
|
for prefix in tag_prefixes:
|
||||||
|
tag_filter.append(tags[f"{prefix}:{k}"] == v)
|
||||||
|
|
||||||
return tag_filter
|
return tag_filter
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue