mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-01-31 15:19:10 +00:00
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:
committed by
GitHub
parent
4f9d805cac
commit
781aca27ae
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user