mirror of
https://github.com/beetbox/beets.git
synced 2026-01-03 22:42:44 +01:00
mbsync: avoid spurious stores/moves
As _print_and_apply_changes itself does for items, we now shortcut modifications (metadata and filesystem) for albums when no changes are required for a given album. This avoids effectively doing a "beet move" on an album even when nothing has changed.
This commit is contained in:
parent
5f68d03793
commit
18688008a4
1 changed files with 12 additions and 2 deletions
|
|
@ -25,12 +25,15 @@ log = logging.getLogger('beets')
|
|||
|
||||
|
||||
def _print_and_apply_changes(lib, item, move, pretend, write):
|
||||
"""Apply changes to an Item and preview them in the console. Return
|
||||
a boolean indicating whether any changes were made.
|
||||
"""
|
||||
changes = {}
|
||||
for key in library.ITEM_KEYS_META:
|
||||
if item.dirty[key]:
|
||||
changes[key] = item.old_data[key], getattr(item, key)
|
||||
if not changes:
|
||||
return
|
||||
return False
|
||||
|
||||
# Something changed.
|
||||
ui.print_obj(item, lib)
|
||||
|
|
@ -47,6 +50,8 @@ def _print_and_apply_changes(lib, item, move, pretend, write):
|
|||
item.write()
|
||||
lib.store(item)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def mbsync_singletons(lib, query, move, pretend, write):
|
||||
"""Synchronize matching singleton items.
|
||||
|
|
@ -104,8 +109,13 @@ def mbsync_albums(lib, query, move, pretend, write):
|
|||
# Apply.
|
||||
with lib.transaction():
|
||||
autotag.apply_metadata(album_info, mapping)
|
||||
changed = False
|
||||
for item in items:
|
||||
_print_and_apply_changes(lib, item, move, pretend, write)
|
||||
changed = changed or \
|
||||
_print_and_apply_changes(lib, item, move, pretend, write)
|
||||
if not changed:
|
||||
# No change to any item.
|
||||
continue
|
||||
|
||||
if not pretend:
|
||||
# Update album structure to reflect an item in it.
|
||||
|
|
|
|||
Loading…
Reference in a new issue