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
This commit is contained in:
Travis Abendshien
2025-09-01 15:14:09 -07:00
committed by GitHub
parent 4f9d805cac
commit 781aca27ae

View File

@@ -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