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 the metadata of these files. The 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 unused data if the database is "prunable" and the current synchronization is not the first synchronization of the mediastore.

A database is prunable if its configuration allows for unused data to be deleted. Pruning is the name of the technique used during database cleanup to incrementally remove unneeded database entries.

The files pass (the first synchronization pass) identifies the media currently stored on the device. As part of 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 from any metadata tables defined in a custom configuration. The database then remains a manageable size and its content reflects what is stored on the media.

The playlist pass (the third synchronization pass) resolves the playlist information. During this pass, mm-sync deletes from the playlist and playlist_entries tables all entries for playlist content no longer on the mediastore.

The cleanup continues as mm-sync then prunes the audio_metadata, video_metadata, photo_metadata, genres, artists, and albums tables to delete the metadata for files removed from the media.

The cleanup can take up to several seconds, depending on the size of the database for the device being synchronized. Clients monitoring the synchronization might therefore see a delay between the receipt of the event signaling the completion of the playlist pass (the third pass) and the event signaling the completion of the entire synchronization operation. Furthermore, the QDB database service, which manages the databases mm-sync uses, can consume a large portion of CPU resources throughout the operation.