From 22296056722a229988a87d018a6e409f25655224 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 31 Oct 2023 14:40:07 +0000 Subject: [PATCH] Avoid making queries with 100s of parameters --- matcher/api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/matcher/api.py b/matcher/api.py index b38b6e8..b456457 100644 --- a/matcher/api.py +++ b/matcher/api.py @@ -550,18 +550,23 @@ def get_tag_filter( tags: sqlalchemy.sql.schema.Column, tag_list: list[str] ) -> list[sqlalchemy.sql.elements.BooleanClauseList]: tag_filter = [] + + include_prefix = len(tag_list) < 10 + for tag_or_key in tag_list: if tag_or_key.startswith("Key:"): key = tag_or_key[4:] tag_filter.append(and_(tags.has_key(key), tags[key] != "no")) - for prefix in tag_prefixes: - tag_filter.append(tags.has_key(f"{prefix}:{key}")) + if include_prefix: + for prefix in tag_prefixes: + tag_filter.append(tags.has_key(f"{prefix}:{key}")) if tag_or_key.startswith("Tag:"): k, _, v = tag_or_key[4:].partition("=") tag_filter.append(tags[k] == v) - for prefix in tag_prefixes: - tag_filter.append(tags[f"{prefix}:{k}"] == v) + if include_prefix: + for prefix in tag_prefixes: + tag_filter.append(tags[f"{prefix}:{k}"] == v) return tag_filter