dovecot-1.0: Optimize physical mail size calculation by using th...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Dec 4 15:15:14 EET 2007
details: http://hg.dovecot.org/dovecot-1.0/rev/212777918121
changeset: 5483:212777918121
user: Timo Sirainen <tss at iki.fi>
date: Tue Dec 04 15:14:35 2007 +0200
description:
Optimize physical mail size calculation by using the next message's offset
or the mbox size for the last message.
diffstat:
3 files changed, 45 insertions(+), 5 deletions(-)
src/lib-storage/index/mbox/mbox-file.c | 21 +++++++++++++++++----
src/lib-storage/index/mbox/mbox-file.h | 3 +++
src/lib-storage/index/mbox/mbox-mail.c | 26 +++++++++++++++++++++++++-
diffs (98 lines):
diff -r 30fbd49c39bf -r 212777918121 src/lib-storage/index/mbox/mbox-file.c
--- a/src/lib-storage/index/mbox/mbox-file.c Tue Dec 04 10:26:25 2007 +0200
+++ b/src/lib-storage/index/mbox/mbox-file.c Tue Dec 04 15:14:35 2007 +0200
@@ -146,11 +146,11 @@ void mbox_file_close_stream(struct mbox_
}
}
-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, bool *deleted_r)
{
const void *data;
- uint64_t offset;
int ret;
*deleted_r = FALSE;
@@ -172,7 +172,20 @@ int mbox_file_seek(struct mbox_mailbox *
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, deleted_r);
+ if (ret <= 0)
+ return ret;
+
if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
if (offset == 0) {
mail_storage_set_error(STORAGE(mbox->storage),
diff -r 30fbd49c39bf -r 212777918121 src/lib-storage/index/mbox/mbox-file.h
--- a/src/lib-storage/index/mbox/mbox-file.h Tue Dec 04 10:26:25 2007 +0200
+++ b/src/lib-storage/index/mbox/mbox-file.h Tue Dec 04 15:14:35 2007 +0200
@@ -7,6 +7,9 @@ int mbox_file_open_stream(struct mbox_ma
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, bool *deleted_r);
int mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view,
uint32_t seq, bool *deleted_r);
diff -r 30fbd49c39bf -r 212777918121 src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c Tue Dec 04 10:26:25 2007 +0200
+++ b/src/lib-storage/index/mbox/mbox-mail.c Tue Dec 04 15:14:35 2007 +0200
@@ -157,8 +157,11 @@ static uoff_t mbox_mail_get_physical_siz
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;
+ bool deleted;
if (mbox_mail_seek(mail) <= 0)
return (uoff_t)-1;
@@ -169,7 +172,28 @@ static uoff_t mbox_mail_get_physical_siz
body_offset = istream_raw_mbox_get_body_offset(stream);
if (body_offset == (uoff_t)-1)
return (uoff_t)-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 = (STORAGE(mbox->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,
+ &deleted) > 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;
return data->physical_size;
More information about the dovecot-cvs
mailing list