Skip to content

Commit 940617c

Browse files
fix(library): get_tag_by_name (#1006)
1 parent 9b287cb commit 940617c

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def get_paths(self, glob: str | None = None, limit: int = -1) -> list[str]:
858858
def search_library(
859859
self,
860860
search: BrowsingState,
861-
page_size: int,
861+
page_size: int | None,
862862
) -> SearchResult:
863863
"""Filter library by search query.
864864
@@ -903,7 +903,8 @@ def search_library(
903903
sort_on = func.lower(Entry.path)
904904

905905
statement = statement.order_by(asc(sort_on) if search.ascending else desc(sort_on))
906-
statement = statement.limit(page_size).offset(search.page_index * page_size)
906+
if page_size is not None:
907+
statement = statement.limit(page_size).offset(search.page_index * page_size)
907908

908909
logger.info(
909910
"searching library",
@@ -1425,23 +1426,38 @@ def get_tag(self, tag_id: int) -> Tag | None:
14251426
)
14261427
tag = session.scalar(tags_query.where(Tag.id == tag_id))
14271428

1428-
session.expunge(tag)
1429-
for parent in tag.parent_tags:
1430-
session.expunge(parent)
1429+
if tag is not None:
1430+
session.expunge(tag)
14311431

1432-
for alias in tag.aliases:
1433-
session.expunge(alias)
1432+
for parent in tag.parent_tags:
1433+
session.expunge(parent)
1434+
1435+
for alias in tag.aliases:
1436+
session.expunge(alias)
14341437

14351438
return tag
14361439

14371440
def get_tag_by_name(self, tag_name: str) -> Tag | None:
14381441
with Session(self.engine) as session:
14391442
statement = (
14401443
select(Tag)
1444+
.options(selectinload(Tag.parent_tags), selectinload(Tag.aliases))
14411445
.outerjoin(TagAlias)
14421446
.where(or_(Tag.name == tag_name, TagAlias.name == tag_name))
14431447
)
1444-
return session.scalar(statement)
1448+
1449+
tag = session.scalar(statement)
1450+
1451+
if tag is not None:
1452+
session.expunge(tag)
1453+
1454+
for parent in tag.parent_tags:
1455+
session.expunge(parent)
1456+
1457+
for alias in tag.aliases:
1458+
session.expunge(alias)
1459+
1460+
return tag
14451461

14461462
def get_alias(self, tag_id: int, alias_id: int) -> TagAlias | None:
14471463
with Session(self.engine) as session:

0 commit comments

Comments
 (0)