fix: cleanup imap and imap_sync records without transport in housekeeping

Previously transports deleted via sync messages left unused `imap` entries.
This commit is contained in:
link2xt
2026-03-26 05:03:30 +01:00
committed by l
parent c8716ad85a
commit b87805ab24
2 changed files with 18 additions and 5 deletions

View File

@@ -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)