Function cleanup_duplicate_keys_internal

Source
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 removed
  • Err(anyhow::Error) - Failed to clean up duplicate keys

§Process

For each key with multiple entries, this function:

  1. Identifies the most recently updated entry by updated_at timestamp
  2. Deletes all other entries with the same key
  3. 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.