Database cleanup

During synchronization, mm-sync may clean up the database to remove references to files no longer on the mediastore and unused references to their metadata. This cleanup ensures the accuracy of the content and responsiveness of the database by eliminating unneeded, stale data.

The multimedia synchronizer may attempt to clean up the database if it's prunable, meaning its configuration allows for unused data to be deleted, and if the current synchronization is not the first one for the mediastore.

The files pass (the first pass) identifies currently accessible media files. In this activity, mm-sync deletes from the files, folders, playlist, and playlist_entries tables all entries for content not found on the mediastore. Any metadata for this nonexistent content is deleted from the audio_metadata, video_metadata, and photo_metadata tables, or any metadata tables defined in a custom configuration. The database then remains a manageable size and reflects what is actually on the mediastore.

No cleanup is done during the metadata pass (the second pass) but in the playlist pass (the third pass), mm-sync deletes from the playlist and playlist_entries tables all entries for playlist content no longer on the mediastore.

After this last pass, the cleanup continues as mm-sync prunes the audio_metadata, video_metadata, photo_metadata, genres, artists, and albums tables to delete the metadata for files that were removed since the last synchronization. This activity can take several seconds, depending on the database size. Clients monitoring the synchronization might therefore see a delay between the receipt of the events signalling the completion of the playlist pass and the completion of the entire operation.