dovecot: Cleanups/rewrites to how/when date/size caching is done.
dovecot at dovecot.org
dovecot at dovecot.org
Thu Nov 22 09:37:01 EET 2007
details: http://hg.dovecot.org/dovecot/rev/d2c8269a0679
changeset: 6842:d2c8269a0679
user: Timo Sirainen <tss at iki.fi>
date: Thu Nov 22 09:36:57 2007 +0200
description:
Cleanups/rewrites to how/when date/size caching is done.
diffstat:
7 files changed, 225 insertions(+), 165 deletions(-)
src/lib-storage/index/cydir/cydir-mail.c | 19 ---
src/lib-storage/index/dbox/dbox-mail.c | 26 +---
src/lib-storage/index/index-mail-headers.c | 30 +++--
src/lib-storage/index/index-mail.c | 148 ++++++++++++++++----------
src/lib-storage/index/index-mail.h | 5
src/lib-storage/index/maildir/maildir-mail.c | 127 +++++++++++++---------
src/lib-storage/index/mbox/mbox-mail.c | 35 ++++--
diffs (truncated from 785 to 300 lines):
diff -r 0c970b3493ac -r d2c8269a0679 src/lib-storage/index/cydir/cydir-mail.c
--- a/src/lib-storage/index/cydir/cydir-mail.c Thu Nov 22 07:56:38 2007 +0200
+++ b/src/lib-storage/index/cydir/cydir-mail.c Thu Nov 22 09:36:57 2007 +0200
@@ -40,17 +40,14 @@ static int cydir_mail_get_received_date(
struct index_mail *mail = (struct index_mail *)_mail;
struct index_mail_data *data = &mail->data;
struct stat st;
- uint32_t t;
- (void)index_mail_get_received_date(_mail, date_r);
- if (*date_r != (time_t)-1)
+ if (index_mail_get_received_date(_mail, date_r) == 0)
return 0;
if (cydir_mail_stat(_mail, &st) < 0)
return -1;
- data->received_date = t = st.st_mtime;
- index_mail_cache_add(mail, MAIL_CACHE_RECEIVED_DATE, &t, sizeof(t));
+ data->received_date = st.st_mtime;
*date_r = data->received_date;
return 0;
}
@@ -60,17 +57,14 @@ static int cydir_mail_get_save_date(stru
struct index_mail *mail = (struct index_mail *)_mail;
struct index_mail_data *data = &mail->data;
struct stat st;
- uint32_t t;
- (void)index_mail_get_save_date(_mail, date_r);
- if (*date_r != (time_t)-1)
+ if (index_mail_get_save_date(_mail, date_r) == 0)
return 0;
if (cydir_mail_stat(_mail, &st) < 0)
return (time_t)-1;
- data->save_date = t = st.st_ctime;
- index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
+ data->save_date = st.st_ctime;
*date_r = data->save_date;
return 0;
}
@@ -81,16 +75,13 @@ static int cydir_mail_get_physical_size(
struct index_mail_data *data = &mail->data;
struct stat st;
- (void)index_mail_get_physical_size(_mail, size_r);
- if (*size_r != (uoff_t)-1)
+ if (index_mail_get_physical_size(_mail, size_r) == 0)
return 0;
if (cydir_mail_stat(_mail, &st) < 0)
return -1;
data->physical_size = data->virtual_size = st.st_size;
- index_mail_cache_add(mail, MAIL_CACHE_PHYSICAL_FULL_SIZE,
- &data->physical_size, sizeof(data->physical_size));
*size_r = data->physical_size;
return 0;
}
diff -r 0c970b3493ac -r d2c8269a0679 src/lib-storage/index/dbox/dbox-mail.c
--- a/src/lib-storage/index/dbox/dbox-mail.c Thu Nov 22 07:56:38 2007 +0200
+++ b/src/lib-storage/index/dbox/dbox-mail.c Thu Nov 22 09:36:57 2007 +0200
@@ -91,19 +91,15 @@ static int dbox_mail_get_received_date(s
struct index_mail_data *data = &mail->imail.data;
struct dbox_file *file;
const char *value;
- uint32_t t;
-
- (void)index_mail_get_received_date(_mail, date_r);
- if (*date_r != (time_t)-1)
+
+ if (index_mail_get_received_date(_mail, date_r) == 0)
return 0;
if (dbox_mail_metadata_seek(mail, &file) < 0)
return -1;
value = dbox_file_metadata_get(file, DBOX_METADATA_RECEIVED_TIME);
- data->received_date = t = value == NULL ? 0 : strtoul(value, NULL, 16);
- index_mail_cache_add(&mail->imail, MAIL_CACHE_RECEIVED_DATE,
- &t, sizeof(t));
+ data->received_date = value == NULL ? 0 : strtoul(value, NULL, 16);
*date_r = data->received_date;
return 0;
}
@@ -114,18 +110,15 @@ static int dbox_mail_get_save_date(struc
struct index_mail_data *data = &mail->imail.data;
struct dbox_file *file;
const char *value;
- uint32_t t;
-
- (void)index_mail_get_save_date(_mail, date_r);
- if (*date_r != (time_t)-1)
+
+ if (index_mail_get_save_date(_mail, date_r) == 0)
return 0;
if (dbox_mail_metadata_seek(mail, &file) < 0)
return -1;
value = dbox_file_metadata_get(file, DBOX_METADATA_SAVE_TIME);
- data->save_date = t = value == NULL ? 0 : strtoul(value, NULL, 16);
- index_mail_cache_add(&mail->imail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
+ data->save_date = value == NULL ? 0 : strtoul(value, NULL, 16);
*date_r = data->save_date;
return 0;
}
@@ -148,8 +141,6 @@ static int dbox_mail_get_virtual_size(st
return index_mail_get_virtual_size(_mail, size_r);
data->virtual_size = strtoul(value, NULL, 16);
- index_mail_cache_add(&mail->imail, MAIL_CACHE_VIRTUAL_FULL_SIZE,
- &data->virtual_size, sizeof(data->virtual_size));
*size_r = data->virtual_size;
return 0;
}
@@ -160,16 +151,13 @@ static int dbox_mail_get_physical_size(s
struct index_mail_data *data = &mail->data;
struct istream *input;
- (void)index_mail_get_physical_size(_mail, size_r);
- if (*size_r != (uoff_t)-1)
+ if (index_mail_get_physical_size(_mail, size_r) == 0)
return 0;
if (mail_get_stream(_mail, NULL, NULL, &input) < 0)
return -1;
i_assert(data->physical_size != (uoff_t)-1);
- index_mail_cache_add(mail, MAIL_CACHE_PHYSICAL_FULL_SIZE,
- &data->physical_size, sizeof(data->physical_size));
*size_r = data->physical_size;
return 0;
}
diff -r 0c970b3493ac -r d2c8269a0679 src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c Thu Nov 22 07:56:38 2007 +0200
+++ b/src/lib-storage/index/index-mail-headers.c Thu Nov 22 09:36:57 2007 +0200
@@ -164,8 +164,14 @@ get_header_field_idx(struct index_mailbo
bool index_mail_want_parse_headers(struct index_mail *mail)
{
- return mail->wanted_headers != NULL || mail->data.save_sent_date ||
- mail->data.save_bodystructure_header;
+ if (mail->wanted_headers != NULL ||
+ mail->data.save_bodystructure_header)
+ return TRUE;
+
+ if ((mail->data.cache_fetch_fields & MAIL_FETCH_DATE) != 0 &&
+ !mail->data.sent_date_parsed)
+ return TRUE;
+ return FALSE;
}
void index_mail_parse_header_init(struct index_mail *mail,
@@ -213,9 +219,7 @@ void index_mail_parse_header_init(struct
}
}
- if (mail->data.save_sent_date) {
- mail->data.save_sent_date = FALSE;
-
+ if ((mail->data.cache_fetch_fields & MAIL_FETCH_DATE) != 0) {
array_idx_set(&mail->header_match,
get_header_field_idx(mail->ibox, "Date"),
&mail->header_match_value);
@@ -242,13 +246,18 @@ static void index_mail_parse_finish_imap
static void index_mail_parse_finish_imap_envelope(struct index_mail *mail)
{
string_t *str;
+ unsigned int cache_field;
str = str_new(mail->data_pool, 256);
imap_envelope_write_part_data(mail->data.envelope_data, str);
mail->data.envelope = str_c(str);
- index_mail_cache_add(mail, MAIL_CACHE_IMAP_ENVELOPE,
- str_data(str), str_len(str));
+ cache_field = mail->ibox->cache_fields[MAIL_CACHE_IMAP_ENVELOPE].idx;
+ if (mail_cache_field_want_add(mail->trans->cache_trans,
+ mail->data.seq, cache_field)) {
+ index_mail_cache_add_idx(mail, cache_field,
+ str_data(str), str_len(str));
+ }
}
void index_mail_parse_header(struct message_part *part,
@@ -277,11 +286,8 @@ void index_mail_parse_header(struct mess
if (hdr == NULL) {
/* end of headers */
- if (data->sent_date.time != (uint32_t)-1) {
- index_mail_cache_add(mail, MAIL_CACHE_SENT_DATE,
- &data->sent_date,
- sizeof(data->sent_date));
- }
+ if (mail->data.save_sent_date)
+ mail->data.sent_date_parsed = TRUE;
index_mail_parse_header_finish(mail);
data->save_bodystructure_header = FALSE;
return;
diff -r 0c970b3493ac -r d2c8269a0679 src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c Thu Nov 22 07:56:38 2007 +0200
+++ b/src/lib-storage/index/index-mail.c Thu Nov 22 09:36:57 2007 +0200
@@ -164,6 +164,7 @@ int index_mail_get_parts(struct mail *_m
struct index_mail *mail = (struct index_mail *)_mail;
struct index_mail_data *data = &mail->data;
+ data->cache_fetch_fields |= MAIL_FETCH_MESSAGE_PARTS;
if (data->parts != NULL || get_cached_parts(mail)) {
*parts_r = data->parts;
return 0;
@@ -187,6 +188,7 @@ int index_mail_get_received_date(struct
struct index_mail *mail = (struct index_mail *)_mail;
struct index_mail_data *data = &mail->data;
+ data->cache_fetch_fields |= MAIL_FETCH_RECEIVED_DATE;
if (data->received_date == (time_t)-1) {
uint32_t t;
@@ -196,7 +198,7 @@ int index_mail_get_received_date(struct
}
*date_r = data->received_date;
- return 0;
+ return *date_r == (time_t)-1 ? -1 : 0;
}
int index_mail_get_save_date(struct mail *_mail, time_t *date_r)
@@ -204,6 +206,7 @@ int index_mail_get_save_date(struct mail
struct index_mail *mail = (struct index_mail *)_mail;
struct index_mail_data *data = &mail->data;
+ data->cache_fetch_fields |= MAIL_FETCH_SAVE_DATE;
if (data->save_date == (time_t)-1) {
uint32_t t;
@@ -213,7 +216,7 @@ int index_mail_get_save_date(struct mail
}
*date_r = data->save_date;
- return 0;
+ return *date_r == (time_t)-1 ? -1 : 0;
}
static int index_mail_cache_sent_date(struct index_mail *mail)
@@ -248,6 +251,7 @@ int index_mail_get_date(struct mail *_ma
struct index_mail *mail = (struct index_mail *)_mail;
struct index_mail_data *data = &mail->data;
+ data->cache_fetch_fields |= MAIL_FETCH_DATE;
if (data->sent_date.time != (uint32_t)-1) {
*date_r = data->sent_date.time;
return 0;
@@ -288,6 +292,7 @@ static bool get_cached_msgpart_sizes(str
bool index_mail_get_cached_virtual_size(struct index_mail *mail, uoff_t *size_r)
{
+ mail->data.cache_fetch_fields |= MAIL_FETCH_VIRTUAL_SIZE;
if (mail->data.virtual_size == (uoff_t)-1) {
if (!index_mail_get_cached_uoff_t(mail,
MAIL_CACHE_VIRTUAL_FULL_SIZE,
@@ -317,8 +322,6 @@ int index_mail_get_virtual_size(struct m
i_stream_seek(data->stream, old_offset);
i_assert(data->virtual_size != (uoff_t)-1);
- index_mail_cache_add(mail, MAIL_CACHE_VIRTUAL_FULL_SIZE,
- &data->virtual_size, sizeof(data->virtual_size));
*size_r = data->virtual_size;
return 0;
}
@@ -328,6 +331,7 @@ int index_mail_get_physical_size(struct
struct index_mail *mail = (struct index_mail *)_mail;
struct index_mail_data *data = &mail->data;
+ data->cache_fetch_fields |= MAIL_FETCH_PHYSICAL_SIZE;
if (data->physical_size == (uoff_t)-1) {
if (!index_mail_get_cached_uoff_t(mail,
MAIL_CACHE_PHYSICAL_FULL_SIZE,
@@ -335,7 +339,7 @@ int index_mail_get_physical_size(struct
(void)get_cached_msgpart_sizes(mail);
}
*size_r = data->physical_size;
- return 0;
+ return *size_r == (uoff_t)-1 ? -1 : 0;
}
void index_mail_cache_add(struct index_mail *mail, enum index_cache_field field,
@@ -465,8 +469,7 @@ static void index_mail_body_parsed_cache
t_push();
buffer = buffer_create_dynamic(pool_datastack_create(), 1024);
message_part_serialize(mail->data.parts, buffer);
- index_mail_cache_add(mail, MAIL_CACHE_MESSAGE_PARTS,
- buffer->data, buffer->used);
+ index_mail_cache_add_idx(mail, cache_field, buffer->data, buffer->used);
t_pop();
data->messageparts_saved_to_cache = TRUE;
@@ -560,28 +563,91 @@ index_mail_body_parsed_cache_bodystructu
More information about the dovecot-cvs
mailing list