beets icon indicating copy to clipboard operation
beets copied to clipboard

Avoid unnecessary writes when modifying non-media fields

Open weiqianwang123 opened this issue 1 month ago • 1 comments

Summary

Some beets commands such as:

beet modify -a onplayer=true queen

update only custom fields that are not mapped to media tags. However, the current implementation still performs MediaFile.save(), causing:

unnecessary file writes

updated mtimes

20–30 second delays on large libraries

slow iPod sync / alternative device workflows

Root Cause

Item.write() filters _media_fields, but it always writes even if:

none of the media-tag fields changed

only flexible/custom database fields changed

Fix

Before writing, compute whether any media-tag-backed field changed. If no media tag differences exist, skip the write entirely.

This preserves existing behavior for:

imports

replaygain

zero / scrub

metadata updates

Testing

A 0.5s sine-wave mp3 was generated via ffmpeg:

ffmpeg -f lavfi -i sine=frequency=440:duration=0.5 tiny.mp3 beet import tiny.mp3

Then:

Should NOT write to file

beet modify -a onplayer=true tiny

Should write to file

beet modify title="new title" tiny

Screenshots attached.

Performance improvement

Before: 25 seconds After: <1 second (repeated 200× batch modify)

DCO

All commits signed-off.

Related Issue: #5668

weiqianwang123 avatar Dec 08 '25 02:12 weiqianwang123

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

github-actions[bot] avatar Dec 08 '25 02:12 github-actions[bot]

Hi! Thanks for the PR. It looks like the current approach is causing side effects that break the current test suite, possibly due to an indentation error on this line. A test for a change like this would also be good, especially since it's dealing with core code, to make sure we're not making the performance issues worse.

henry-oberholtzer avatar Dec 17 '25 05:12 henry-oberholtzer