Avoid making queries with 100s of parameters
This commit is contained in:
parent
bf98eb71dc
commit
2229605672
|
@ -550,16 +550,21 @@ 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"))
|
||||||
|
if include_prefix:
|
||||||
for prefix in tag_prefixes:
|
for prefix in tag_prefixes:
|
||||||
tag_filter.append(tags.has_key(f"{prefix}:{key}"))
|
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)
|
||||||
|
if include_prefix:
|
||||||
for prefix in tag_prefixes:
|
for prefix in tag_prefixes:
|
||||||
tag_filter.append(tags[f"{prefix}:{k}"] == v)
|
tag_filter.append(tags[f"{prefix}:{k}"] == v)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue