From 781aca27ae0b5c4347f607dee15347152fb23aa9 Mon Sep 17 00:00:00 2001 From: Travis Abendshien <46939827+CyanVoxel@users.noreply.github.com> Date: Mon, 1 Sep 2025 15:14:09 -0700 Subject: [PATCH] fix: don't flush entire changes when adding tags in bulk (#1081) * fix: don't flush entire changes when adding tags in bulk * fix: remove bumped version * fix: remove bumped version, again --- src/tagstudio/core/library/alchemy/library.py | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/tagstudio/core/library/alchemy/library.py b/src/tagstudio/core/library/alchemy/library.py index c4becc3a..fc56f919 100644 --- a/src/tagstudio/core/library/alchemy/library.py +++ b/src/tagstudio/core/library/alchemy/library.py @@ -1433,8 +1433,13 @@ class Library: def add_tags_to_entries( self, entry_ids: int | list[int], tag_ids: int | list[int] | set[int] - ) -> bool: - """Add one or more tags to one or more entries.""" + ) -> int: + """Add one or more tags to one or more entries. + + Returns: + The total number of tags added across all entries. + """ + total_added: int = 0 logger.info( "[Library][add_tags_to_entries]", entry_ids=entry_ids, @@ -1448,16 +1453,12 @@ class Library: for entry_id in entry_ids_: try: session.add(TagEntry(tag_id=tag_id, entry_id=entry_id)) - session.flush() + total_added += 1 + session.commit() except IntegrityError: session.rollback() - try: - session.commit() - except IntegrityError as e: - logger.warning("[Library][add_tags_to_entries]", warning=e) - session.rollback() - return False - return True + + return total_added def remove_tags_from_entries( self, entry_ids: int | list[int], tag_ids: int | list[int] | set[int] @@ -1892,12 +1893,9 @@ class Library: if not result: success = False tag_ids = [tag.id for tag in from_entry.tags] - add_result = self.add_tags_to_entries(into_entry.id, tag_ids) + self.add_tags_to_entries(into_entry.id, tag_ids) self.remove_entries([from_entry.id]) - if not add_result: - success = False - return success @property