Do not write unchanged items to the library in FtInTitle (#5718)

FtInTitle performs a library store operation for every item it
processes, whether or not the item has changed. By limiting the
`item.store()` call to only those cases when the item has changed, the
plugin’s performance when processing an entire library improves by two
to three orders of magnitude.
This commit is contained in:
Peter Dolan 2025-04-14 11:22:41 -07:00 committed by GitHub
parent d447bc3f46
commit 447cc82e04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View file

@ -111,10 +111,10 @@ class FtInTitlePlugin(plugins.BeetsPlugin):
write = ui.should_write()
for item in lib.items(ui.decargs(args)):
self.ft_in_title(item, drop_feat, keep_in_artist_field)
item.store()
if write:
item.try_write()
if self.ft_in_title(item, drop_feat, keep_in_artist_field):
item.store()
if write:
item.try_write()
self._command.func = func
return [self._command]
@ -125,8 +125,8 @@ class FtInTitlePlugin(plugins.BeetsPlugin):
keep_in_artist_field = self.config["keep_in_artist"].get(bool)
for item in task.imported_items():
self.ft_in_title(item, drop_feat, keep_in_artist_field)
item.store()
if self.ft_in_title(item, drop_feat, keep_in_artist_field):
item.store()
def update_metadata(self, item, feat_part, drop_feat, keep_in_artist_field):
"""Choose how to add new artists to the title and set the new
@ -156,9 +156,12 @@ class FtInTitlePlugin(plugins.BeetsPlugin):
self._log.info("title: {0} -> {1}", item.title, new_title)
item.title = new_title
def ft_in_title(self, item, drop_feat, keep_in_artist_field):
def ft_in_title(self, item, drop_feat, keep_in_artist_field) -> bool:
"""Look for featured artists in the item's artist fields and move
them to the title.
Returns:
True if the item has been modified. False otherwise.
"""
artist = item.artist.strip()
albumartist = item.albumartist.strip()
@ -180,5 +183,7 @@ class FtInTitlePlugin(plugins.BeetsPlugin):
self.update_metadata(
item, feat_part, drop_feat, keep_in_artist_field
)
return True
else:
self._log.info("no featuring artists found")
return False

View file

@ -100,6 +100,8 @@ Other changes:
improve useability for new developers.
* :doc:`/plugins/smartplaylist`: URL-encode additional item `fields` within generated
EXTM3U playlists instead of JSON-encoding them.
* :doc:`plugins/ftintitle`: Optimize the plugin by avoiding unnecessary writes
to the database.
2.2.0 (December 02, 2024)
-------------------------