Reorder commit and metadata count logic

Move `tx.commit()?` after counting metadata rows under the old lazy_pk to ensure accurate count before commit. This fixes a potential race or inconsistency where metadata might be updated after commit, leading to incorrect logging of remaining rows under lazy_pk.
This commit is contained in:
2026-03-25 12:47:59 +01:00
parent 04793da52c
commit 8005968ec5

View File

@@ -1137,17 +1137,17 @@ impl DB {
return Err(Error::QueryReturnedNoRows);
}
tx.commit()?;
// Compter les métadonnées encore sous l'ancien lazy_pk (après migration de l'asset)
let meta_under_lazy: i64 = {
let conn = self.lock_conn("update_lazy_to_downloaded_meta_check");
conn.query_row(
// Compter les métadonnées encore sous l'ancien lazy_pk avant le commit
let meta_under_lazy: i64 = tx
.query_row(
"SELECT COUNT(*) FROM metadata WHERE pk = ?1",
[lazy_pk],
|r| r.get(0),
).unwrap_or(0)
};
)
.unwrap_or(0);
tx.commit()?;
tracing::debug!(
"update_lazy_to_downloaded: {} → {} ({} metadata rows still under lazy_pk)",
lazy_pk, real_pk, meta_under_lazy