Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6930:48ddc0c4036c HEAD
Optimize physical mail size calculation by using the next message's offset
or the mbox size for the last message.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 04 Dec 2007 15:20:01 +0200 |
parents | 8c80093fbab4 |
children | 97702c9c4111 |
files | src/lib-storage/index/mbox/mbox-file.c src/lib-storage/index/mbox/mbox-file.h src/lib-storage/index/mbox/mbox-mail.c |
diffstat | 3 files changed, 49 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-file.c Tue Dec 04 14:47:43 2007 +0200 +++ b/src/lib-storage/index/mbox/mbox-file.c Tue Dec 04 15:20:01 2007 +0200 @@ -131,17 +131,15 @@ } } -int mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view, - uint32_t seq, bool *deleted_r) +int mbox_file_lookup_offset(struct mbox_mailbox *mbox, + struct mail_index_view *view, + uint32_t seq, uoff_t *offset_r) { const void *data; - uint64_t offset; - int ret; + bool deleted; - *deleted_r = FALSE; - - mail_index_lookup_ext(view, seq, mbox->mbox_ext_idx, &data, deleted_r); - if (*deleted_r) + mail_index_lookup_ext(view, seq, mbox->mbox_ext_idx, &data, &deleted); + if (deleted) return -1; if (data == NULL) { @@ -152,7 +150,23 @@ return 0; } - offset = *((const uint64_t *)data); + *offset_r = *((const uint64_t *)data); + return 1; +} + +int mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view, + uint32_t seq, bool *deleted_r) +{ + uoff_t offset; + int ret; + + ret = mbox_file_lookup_offset(mbox, view, seq, &offset); + if (ret <= 0) { + *deleted_r = ret < 0; + return ret; + } + *deleted_r = FALSE; + if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) { if (offset == 0) { mail_storage_set_error(&mbox->storage->storage,
--- a/src/lib-storage/index/mbox/mbox-file.h Tue Dec 04 14:47:43 2007 +0200 +++ b/src/lib-storage/index/mbox/mbox-file.h Tue Dec 04 15:20:01 2007 +0200 @@ -7,6 +7,9 @@ int mbox_file_open_stream(struct mbox_mailbox *mbox); void mbox_file_close_stream(struct mbox_mailbox *mbox); +int mbox_file_lookup_offset(struct mbox_mailbox *mbox, + struct mail_index_view *view, + uint32_t seq, uoff_t *offset_r); int mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view, uint32_t seq, bool *deleted_r);
--- a/src/lib-storage/index/mbox/mbox-mail.c Tue Dec 04 14:47:43 2007 +0200 +++ b/src/lib-storage/index/mbox/mbox-mail.c Tue Dec 04 15:20:01 2007 +0200 @@ -171,8 +171,10 @@ struct index_mail *mail = (struct index_mail *)_mail; struct index_mail_data *data = &mail->data; struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + const struct mail_index_header *hdr; struct istream *stream; uoff_t hdr_offset, body_offset, body_size; + uoff_t next_offset; if (mbox_mail_seek(mail) < 0) return -1; @@ -186,7 +188,27 @@ "Couldn't get mbox size"); return -1; } - body_size = istream_raw_mbox_get_body_size(stream, (uoff_t)-1); + + /* use the next message's offset to avoid reading through the entire + message body to find out its size */ + hdr = mail_index_get_header(mail->trans->trans_view); + if (_mail->seq == hdr->messages_count) { + /* last message, use the synced mbox size */ + int trailer_size; + + trailer_size = (mbox->storage->storage.flags & + MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? 2 : 1; + + body_size = hdr->sync_size - body_offset - trailer_size; + } else if (mbox_file_lookup_offset(mbox, mail->trans->trans_view, + _mail->seq + 1, &next_offset) > 0) { + body_size = next_offset - body_offset; + } else { + body_size = (uoff_t)-1; + } + + /* verify that the calculated body size is correct */ + body_size = istream_raw_mbox_get_body_size(stream, body_size); data->physical_size = (body_offset - hdr_offset) + body_size; *size_r = data->physical_size;