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)
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. */
return TRUE;
/* already synced */
- return mail_cache_need_purge(index->cache);
+ const char *reason;
+ return mail_cache_need_purge(index->cache, &reason);
}
static int
/* 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