]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Use delayed purge reason for mail_cache_purge_* events
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 31 Aug 2020 14:27:58 +0000 (17:27 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 3 Sep 2020 15:31:01 +0000 (18:31 +0300)
src/lib-index/mail-cache-purge.c
src/lib-index/mail-cache.h
src/lib-index/mail-index-sync.c

index a56e2d842bc2bf9a8dcf766aad0fd6148bc45a19..8d0a7d9aea9fb55fb3d67ec9ac0fa1e81906686d 100644 (file)
@@ -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)
index 0c3abee94ef7c7dba5028cb57bb5ceb6e4b4ba4d..5b943148edd85c6600ca3e47a2ba7dba4de8c871 100644 (file)
@@ -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. */
index 0e17ba1e2400af6b76bdfc7c0df76ae4b7f94f49..dc840170d83daf92b116a026c9dc07f8dacb2b80 100644 (file)
@@ -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