dovecot: mail_cache_field_want_add(): Return TRUE for temp field...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Nov 22 07:56:43 EET 2007
details: http://hg.dovecot.org/dovecot/rev/0c970b3493ac
changeset: 6841:0c970b3493ac
user: Timo Sirainen <tss at iki.fi>
date: Thu Nov 22 07:56:38 2007 +0200
description:
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
adding the field to a new enough message.
diffstat:
4 files changed, 42 insertions(+), 16 deletions(-)
src/lib-index/mail-cache-compress.c | 21 ++++++---------------
src/lib-index/mail-cache-private.h | 1 +
src/lib-index/mail-cache-transaction.c | 18 +++++++++++++++++-
src/lib-index/mail-cache.c | 18 ++++++++++++++++++
diffs (117 lines):
diff -r efec8836586a -r 0c970b3493ac src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache-compress.c Thu Nov 22 07:56:38 2007 +0200
@@ -167,21 +167,6 @@ mail_cache_copy(struct mail_cache *cache
time_t max_drop_time;
view = mail_index_transaction_get_view(trans);
-
- /* get sequence of first message which doesn't need its temp fields
- removed. */
- idx_hdr = mail_index_get_header(view);
- if (idx_hdr->day_first_uid[7] == 0) {
- first_new_seq = 1;
- message_count = mail_index_view_get_messages_count(view);
- } else {
- if (!mail_index_lookup_seq_range(view,
- idx_hdr->day_first_uid[7],
- (uint32_t)-1, &first_new_seq,
- &message_count))
- first_new_seq = message_count+1;
- }
-
cache_view = mail_cache_view_open(cache, view);
output = o_stream_create_fd_file(fd, 0, FALSE);
@@ -202,6 +187,7 @@ mail_cache_copy(struct mail_cache *cache
/* @UNSAFE: drop unused fields and create a field mapping for
used fields */
+ idx_hdr = mail_index_get_header(view);
max_drop_time = idx_hdr->day_stamp == 0 ? 0 :
idx_hdr->day_stamp - MAIL_CACHE_FIELD_DROP_SECS;
@@ -227,6 +213,11 @@ mail_cache_copy(struct mail_cache *cache
(uint32_t)-1 : used_fields_count++;
}
}
+
+ /* get sequence of first message which doesn't need its temp fields
+ removed. */
+ first_new_seq = mail_cache_get_first_new_seq(view);
+ message_count = mail_index_view_get_messages_count(view);
i_array_init(ext_offsets, message_count);
for (seq = 1; seq <= message_count; seq++) {
diff -r efec8836586a -r 0c970b3493ac src/lib-index/mail-cache-private.h
--- a/src/lib-index/mail-cache-private.h Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache-private.h Thu Nov 22 07:56:38 2007 +0200
@@ -231,6 +231,7 @@ int mail_cache_header_fields_get_next_of
int mail_cache_get_record(struct mail_cache *cache, uint32_t offset,
const struct mail_cache_record **rec_r);
+uint32_t mail_cache_get_first_new_seq(struct mail_index_view *view);
/* Returns TRUE if offset is already in given array. Otherwise return FALSE
and add the offset to the array. */
diff -r efec8836586a -r 0c970b3493ac src/lib-index/mail-cache-transaction.c
--- a/src/lib-index/mail-cache-transaction.c Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache-transaction.c Thu Nov 22 07:56:38 2007 +0200
@@ -27,6 +27,7 @@ struct mail_cache_transaction_ctx {
struct mail_index_transaction *trans;
uint32_t cache_file_seq;
+ uint32_t first_new_seq;
buffer_t *cache_data;
ARRAY_DEFINE(cache_data_seq, uint32_t);
@@ -965,8 +966,23 @@ bool mail_cache_field_want_add(struct ma
mail_cache_transaction_open_if_needed(ctx);
decision = mail_cache_field_get_decision(ctx->view->cache, field_idx);
- if ((decision & ~MAIL_CACHE_DECISION_FORCED) == MAIL_CACHE_DECISION_NO)
+ decision &= ~MAIL_CACHE_DECISION_FORCED;
+ switch (decision) {
+ case MAIL_CACHE_DECISION_NO:
return FALSE;
+ case MAIL_CACHE_DECISION_TEMP:
+ /* add it only if it's newer than what we would drop when
+ compressing */
+ if (ctx->first_new_seq == 0) {
+ ctx->first_new_seq =
+ mail_cache_get_first_new_seq(ctx->view->view);
+ }
+ if (seq < ctx->first_new_seq)
+ return FALSE;
+ break;
+ default:
+ break;
+ }
return mail_cache_field_exists(ctx->view, seq, field_idx) == 0;
}
diff -r efec8836586a -r 0c970b3493ac src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache.c Thu Nov 22 07:56:38 2007 +0200
@@ -669,3 +669,21 @@ void mail_cache_view_close(struct mail_c
buffer_free(&view->cached_exists_buf);
i_free(view);
}
+
+uint32_t mail_cache_get_first_new_seq(struct mail_index_view *view)
+{
+ const struct mail_index_header *idx_hdr;
+ uint32_t first_new_seq, message_count;
+
+ idx_hdr = mail_index_get_header(view);
+ if (idx_hdr->day_first_uid[7] == 0)
+ return 1;
+
+ if (!mail_index_lookup_seq_range(view, idx_hdr->day_first_uid[7],
+ (uint32_t)-1, &first_new_seq,
+ &message_count)) {
+ /* all messages are too old */
+ return message_count+1;
+ }
+ return first_new_seq;
+}
More information about the dovecot-cvs
mailing list