if (hdr->day_stamp != 0) {
const struct mail_index_cache_optimization_settings *opt =
&cache->index->optimization_set.cache;
- ctx_r->max_yes_downgrade_time = hdr->day_stamp -
- opt->unaccessed_field_drop_secs;
- ctx_r->max_temp_drop_time = hdr->day_stamp -
- 2 * opt->unaccessed_field_drop_secs;
+ long threshold = opt->unaccessed_field_drop_secs;
+
+ /* While cache max headers count is saturated, shrink the actual
+ value of this parameter to 1/4, so that the cache can return
+ quicker to the intended state. */
+ if (mail_cache_headers_check_capped(cache))
+ threshold /= 4;
+
+ ctx_r->max_yes_downgrade_time = hdr->day_stamp - threshold;
+ ctx_r->max_temp_drop_time = hdr->day_stamp - 2 * threshold;
}
}
test_end();
}
+static void test_mail_cache_purge_deadlines(void)
+{
+ static const uint32_t BASE_TIME = 1000;
+ static const uint32_t DROP_SECS = 100;
+
+ struct mail_cache cache;
+ struct mail_index index;
+ struct mail_index_header hdr;
+ struct mail_cache_purge_drop_ctx ctx;
+
+ i_zero(&cache);
+ i_zero(&index);
+ i_zero(&hdr);
+ i_zero(&ctx);
+
+ hdr.day_stamp = BASE_TIME;
+ index.optimization_set.cache.unaccessed_field_drop_secs = DROP_SECS;
+ index.optimization_set.cache.max_headers_count = 1;
+ cache.index = &index;
+
+ test_begin("mail cache purge deadlines");
+
+ mail_cache_purge_drop_init(&cache, &hdr, &ctx);
+ test_assert_cmp(cache.headers_capped, ==, FALSE);
+ test_assert_cmp(ctx.max_yes_downgrade_time, ==, BASE_TIME - DROP_SECS);
+ test_assert_cmp(ctx.max_temp_drop_time, ==, BASE_TIME - DROP_SECS - DROP_SECS);
+
+ cache.headers_capped = TRUE;
+ mail_cache_purge_drop_init(&cache, &hdr, &ctx);
+ test_assert_cmp(cache.headers_capped, ==, TRUE);
+ test_assert_cmp(ctx.max_yes_downgrade_time, ==, BASE_TIME - DROP_SECS/4);
+ test_assert_cmp(ctx.max_temp_drop_time, ==, BASE_TIME - DROP_SECS/4 - DROP_SECS/4);
+
+ test_end();
+}
+
int main(void)
{
static void (*const test_functions[])(void) = {
test_mail_cache_update_need_purge_continued_records2,
test_mail_cache_update_need_purge_deleted_records,
test_mail_cache_update_need_purge_deleted_records2,
+ test_mail_cache_purge_deadlines,
NULL
};
return test_run(test_functions);