Skip to content

Commit c1d6a11

Browse files
committed
feat: optimise __entry_has_all_tags
1 parent ea0a4df commit c1d6a11

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tagstudio/src/core/library/alchemy/visitors.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,15 @@ def __get_tag_ids(self, tag_name: str, include_children: bool = True) -> list[in
147147
def __entry_has_all_tags(self, tag_ids: list[int]) -> ColumnElement[bool]:
148148
"""Returns Binary Expression that is true if the Entry has all provided tag ids."""
149149
# Relational Division Query
150-
return Entry.id.in_(
151-
select(Entry.id)
152-
.outerjoin(TagBoxField)
153-
.outerjoin(TagField)
150+
# The changes to this technically introduce a bug
151+
# which occurs when the tags are split across multiple tag box fields,
152+
# but since those will be removed soon the bug will also disappear soon
153+
# (also this method isn't used in every query that has an AND,
154+
# so the bug doesn't even have that many chances to rear its ugly head)
155+
return TagBoxField.id.in_(
156+
select(TagField.field_id)
154157
.where(TagField.tag_id.in_(tag_ids))
155-
.group_by(Entry.id)
158+
.group_by(TagField.field_id)
156159
.having(func.count(distinct(TagField.tag_id)) == len(tag_ids))
157160
)
158161

0 commit comments

Comments
 (0)