From b87805ab240a0172220e69fcfd6e7006dd95c210 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 26 Mar 2026 05:03:30 +0100 Subject: [PATCH] fix: cleanup `imap` and `imap_sync` records without transport in housekeeping Previously transports deleted via sync messages left unused `imap` entries. --- src/configure.rs | 5 ----- src/sql.rs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/configure.rs b/src/configure.rs index e622743b1..40eee7d1a 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -243,11 +243,6 @@ impl Context { Ok((id, add_timestamp)) }, )?; - transaction.execute("DELETE FROM imap WHERE transport_id=?", (transport_id,))?; - transaction.execute( - "DELETE FROM imap_sync WHERE transport_id=?", - (transport_id,), - )?; // Removal timestamp should not be lower than addition timestamp // to be accepted by other devices when synced. diff --git a/src/sql.rs b/src/sql.rs index 912a704a3..609358c69 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -883,6 +883,24 @@ pub async fn housekeeping(context: &Context) -> Result<()> { .log_err(context) .ok(); + // Cleanup `imap` and `imap_sync` entries for deleted transports. + // + // Transports may be deleted directly or via sync messages, + // so it is easier to cleanup orphaned entries in a single place. + context + .sql + .execute( + "DELETE FROM imap WHERE transport_id NOT IN (SELECT transports.id FROM transports)", + (), + ) + .await + .log_err(context) + .ok(); + context.sql.execute( + "DELETE FROM imap_sync WHERE transport_id NOT IN (SELECT transports.id FROM transports)", + (), + ).await.log_err(context).ok(); + // Delete POI locations // which don't have corresponding message. delete_orphaned_poi_locations(context)