From: Timo Sirainen Date: Mon, 31 Aug 2020 14:27:58 +0000 (+0300) Subject: lib-index: Use delayed purge reason for mail_cache_purge_* events X-Git-Tag: 2.3.13~255 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4a85ba0e43cf9958ee4b13542e295ae80e5c7d0;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Use delayed purge reason for mail_cache_purge_* events --- diff --git a/src/lib-index/mail-cache-purge.c b/src/lib-index/mail-cache-purge.c index a56e2d842b..8d0a7d9aea 100644 --- a/src/lib-index/mail-cache-purge.c +++ b/src/lib-index/mail-cache-purge.c @@ -636,11 +636,22 @@ int mail_cache_purge(struct mail_cache *cache, uint32_t purge_file_seq, return ret; } -bool mail_cache_need_purge(struct mail_cache *cache) +bool mail_cache_need_purge(struct mail_cache *cache, const char **reason_r) { - return cache->need_purge_file_seq != 0 && - (cache->index->flags & MAIL_INDEX_OPEN_FLAG_SAVEONLY) == 0 && - !cache->index->readonly; + if (cache->need_purge_file_seq == 0) + return FALSE; /* delayed purging not requested */ + if (cache->index->readonly) + return FALSE; /* no purging when opened as read-only */ + if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_SAVEONLY) != 0) { + /* Mail deliveries don't really need to purge, even if there + could be some work to do. Just delay until the next regular + mail access comes before doing any extra work. */ + return FALSE; + } + + i_assert(cache->need_purge_reason != NULL); + *reason_r = cache->need_purge_reason; + return TRUE; } void mail_cache_purge_later(struct mail_cache *cache, const char *reason) diff --git a/src/lib-index/mail-cache.h b/src/lib-index/mail-cache.h index 0c3abee94e..5b943148ed 100644 --- a/src/lib-index/mail-cache.h +++ b/src/lib-index/mail-cache.h @@ -65,7 +65,7 @@ mail_cache_register_get_list(struct mail_cache *cache, pool_t pool, unsigned int *count_r); /* Returns TRUE if cache should be purged. */ -bool mail_cache_need_purge(struct mail_cache *cache); +bool mail_cache_need_purge(struct mail_cache *cache, const char **reason_r); /* Set cache file to be purged later. */ void mail_cache_purge_later(struct mail_cache *cache, const char *reason); /* Don't try to purge the cache file later after all. */ diff --git a/src/lib-index/mail-index-sync.c b/src/lib-index/mail-index-sync.c index 0e17ba1e24..dc840170d8 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -277,7 +277,8 @@ mail_index_need_sync(struct mail_index *index, enum mail_index_sync_flags flags, return TRUE; /* already synced */ - return mail_cache_need_purge(index->cache); + const char *reason; + return mail_cache_need_purge(index->cache, &reason); } static int @@ -939,11 +940,11 @@ int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx) /* The previously called expunged handlers will update cache's record_count and deleted_record_count. That also has a side effect of updating whether cache needs to be purged. */ - if (ret == 0 && mail_cache_need_purge(index->cache) && + if (ret == 0 && mail_cache_need_purge(index->cache, &reason) && !mail_cache_transactions_have_changes(index->cache)) { if (mail_cache_purge(index->cache, index->cache->need_purge_file_seq, - "syncing") < 0) { + reason) < 0) { /* can't really do anything if it fails */ } /* Make sure the newly committed cache record offsets are