Skip to content

Commit

Permalink
lib-index: Add mail_cache_expunge_count
Browse files Browse the repository at this point in the history
It can be called to correctly handle cache counters
when records are removed.
  • Loading branch information
cmouse authored and GitLab committed May 11, 2017
1 parent 722c977 commit 38228c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/lib-index/mail-cache-private.h
Expand Up @@ -229,6 +229,7 @@ int mail_cache_header_fields_update(struct mail_cache *cache);
void mail_cache_header_fields_get(struct mail_cache *cache, buffer_t *dest);
int mail_cache_header_fields_get_next_offset(struct mail_cache *cache,
uint32_t *offset_r);
void mail_cache_expunge_count(struct mail_cache *cache, unsigned int count);

uint32_t mail_cache_lookup_cur_offset(struct mail_index_view *view,
uint32_t seq, uint32_t *reset_id_r);
Expand Down
27 changes: 15 additions & 12 deletions src/lib-index/mail-cache-sync-update.c
Expand Up @@ -8,6 +8,19 @@ struct mail_cache_sync_context {
unsigned expunge_count;
};

void mail_cache_expunge_count(struct mail_cache *cache, unsigned int count)
{
if (mail_cache_lock(cache) > 0) {
cache->hdr_copy.deleted_record_count += count;
if (cache->hdr_copy.record_count >= count)
cache->hdr_copy.record_count -= count;
else
cache->hdr_copy.record_count = 0;
cache->hdr_modified = TRUE;
(void)mail_cache_unlock(cache);
}
}

static struct mail_cache_sync_context *mail_cache_handler_init(void **context)
{
struct mail_cache_sync_context *ctx;
Expand All @@ -29,18 +42,8 @@ static void mail_cache_handler_deinit(struct mail_index_sync_map_ctx *sync_ctx,
if (ctx == NULL)
return;

if (mail_cache_lock(cache) > 0) {
/* update the record counts in the cache file's header. these
are used to figure out when a cache file should be
recreated and the old data dropped. */
cache->hdr_copy.deleted_record_count += ctx->expunge_count;
if (cache->hdr_copy.record_count >= ctx->expunge_count)
cache->hdr_copy.record_count -= ctx->expunge_count;
else
cache->hdr_copy.record_count = 0;
cache->hdr_modified = TRUE;
(void)mail_cache_unlock(cache);
}
mail_cache_expunge_count(cache, ctx->expunge_count);

i_free(ctx);
}

Expand Down

0 comments on commit 38228c9

Please sign in to comment.