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:
Adrian Sampson 2013-03-03 17:19:05 -08:00
parent 5f68d03793
commit 18688008a4

View file

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