From cccdc51ad40f7c28447b00aff685f108a29976aa Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 30 Jan 2022 23:00:00 +0000 Subject: [PATCH] Optimize delete_expired_imap_messages() For me this reduced query time from 0.3 s to 0.05 s. --- CHANGELOG.md | 6 ++++++ src/ephemeral.rs | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e34570a59..cee6824b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Changes +- optimize `delete_expired_imap_messages()` #3047 + + ## 1.74.0 ### Fixes diff --git a/src/ephemeral.rs b/src/ephemeral.rs index 02f58e456..38f59f241 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -451,12 +451,11 @@ pub(crate) async fn delete_expired_imap_messages(context: &Context) -> Result<() .execute( "UPDATE imap SET target='' - WHERE EXISTS ( - SELECT * FROM msgs - WHERE rfc724_mid=imap.rfc724_mid - AND ((download_state = 0 AND timestamp < ?) OR - (download_state != 0 AND timestamp < ?) OR - (ephemeral_timestamp != 0 AND ephemeral_timestamp <= ?)) + WHERE rfc724_mid IN ( + SELECT rfc724_mid FROM msgs + WHERE ((download_state = 0 AND timestamp < ?) OR + (download_state != 0 AND timestamp < ?) OR + (ephemeral_timestamp != 0 AND ephemeral_timestamp <= ?)) )", paramsv![threshold_timestamp, threshold_timestamp_extended, now], )