async fn cleanup_duplicate_keys_internal(pool: &Pool<MySql>) -> Result<usize>
Expand description
Internal function to clean up duplicate metadata keys.
This function identifies and resolves duplicate keys in the metadata table by keeping only the most recently updated entry for each key. It’s intended for internal use by functions that already hold the metadata mutex.
§Arguments
pool
- Database connection pool for executing the query
§Returns
Ok(usize)
- Number of duplicate entries that were removedErr(anyhow::Error)
- Failed to clean up duplicate keys
§Process
For each key with multiple entries, this function:
- Identifies the most recently updated entry by
updated_at
timestamp - Deletes all other entries with the same key
- Logs a warning if duplicates were found
§Note
This is an internal function not protected by the metadata mutex. It should only be called from functions that already hold the mutex.