]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Moved stats_* from mail to transaction.
authorTimo Sirainen <tss@iki.fi>
Tue, 16 Aug 2011 14:02:08 +0000 (17:02 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 16 Aug 2011 14:02:08 +0000 (17:02 +0300)
With the API changes to search, having them in mail doesn't make sense
anymore, since mailbox_search_next() can return multiple different mails
with different stats.

12 files changed:
src/lib-storage/index/cydir/cydir-mail.c
src/lib-storage/index/dbox-common/dbox-mail.c
src/lib-storage/index/dbox-multi/mdbox-mail.c
src/lib-storage/index/dbox-single/sdbox-mail.c
src/lib-storage/index/index-mail-headers.c
src/lib-storage/index/index-mail.c
src/lib-storage/index/index-search.c
src/lib-storage/index/istream-mail-stats.c
src/lib-storage/index/istream-mail-stats.h
src/lib-storage/index/maildir/maildir-mail.c
src/lib-storage/index/raw/raw-mail.c
src/lib-storage/mail-storage-private.h

index ce24d6e21f2a7219403014fa07ec0ffb5c7b772e..a4aedbd4bacaec246d2cb2fd7d55ffcea6bff772 100644 (file)
@@ -20,13 +20,12 @@ static const char *cydir_mail_get_path(struct mail *mail)
 
 static int cydir_mail_stat(struct mail *mail, struct stat *st_r)
 {
-       struct mail_private *p = (struct mail_private *)mail;
        const char *path;
 
        if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
                return mail_set_aborted(mail);
 
-       p->stats_stat_lookup_count++;
+       mail->transaction->stats_stat_lookup_count++;
        path = cydir_mail_get_path(mail);
        if (stat(path, st_r) < 0) {
                if (errno == ENOENT)
@@ -100,7 +99,7 @@ cydir_mail_get_stream(struct mail *_mail, struct message_size *hdr_size,
        int fd;
 
        if (mail->data.stream == NULL) {
-               mail->mail.stats_open_lookup_count++;
+               _mail->transaction->stats_open_lookup_count++;
                path = cydir_mail_get_path(_mail);
                fd = open(path, O_RDONLY);
                if (fd == -1) {
index c22ba91978cb7f2e00576f94c13892072e2cc82e..fc4806dcd40d8448c9e9a9d5890e463fdbfbdfe5 100644 (file)
@@ -145,7 +145,7 @@ int dbox_mail_get_save_date(struct mail *_mail, time_t *date_r)
        if (storage->v.mail_open(mail, &offset, &file) < 0)
                return -1;
 
-       mail->imail.mail.stats_fstat_lookup_count++;
+       _mail->transaction->stats_fstat_lookup_count++;
        if (dbox_file_stat(file, &st) < 0) {
                if (errno == ENOENT)
                        mail_set_expunged(_mail);
index ce1063c2c09cf3b106ee88d75832c7d2da93b53f..b56c240ac344d65cdba8bd4f5d9612f655bb2cb4 100644 (file)
@@ -126,7 +126,7 @@ int mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
                }
 
                if (!dbox_file_is_open(mail->open_file))
-                       mail->imail.mail.stats_open_lookup_count++;
+                       _mail->transaction->stats_open_lookup_count++;
                if (dbox_file_open(mail->open_file, &deleted) <= 0)
                        return -1;
                if (deleted) {
index d8d00cc40912e899b27a495c67eb296c1190a657..5875bae42f36eaf3804b7d827f97debd6ad7e409 100644 (file)
@@ -68,7 +68,7 @@ int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
 
        if (!sdbox_mail_file_set(mail)) {
                if (!dbox_file_is_open(mail->open_file))
-                       mail->imail.mail.stats_open_lookup_count++;
+                       _mail->transaction->stats_open_lookup_count++;
                if (dbox_file_open(mail->open_file, &deleted) <= 0)
                        return -1;
                if (deleted) {
index aba72d49b9ad8debe4011770d1358640e36467f6..410b9851a330f04a3b653a9a772156384c69d089 100644 (file)
@@ -625,7 +625,7 @@ index_mail_get_raw_headers(struct index_mail *mail, const char *field,
                *value_r = index_mail_get_parsed_header(mail, field_idx);
                return 0;
        }
-       mail->mail.stats_cache_hit_count++;
+       _mail->transaction->stats_cache_hit_count++;
        data = buffer_get_modifiable_data(dest, &len);
 
        if (len == 0) {
@@ -807,7 +807,7 @@ int index_mail_get_header_stream(struct mail *_mail,
        if (mail_cache_lookup_headers(_mail->transaction->cache_view, dest,
                                      _mail->seq, headers->idx,
                                      headers->count) > 0) {
-               mail->mail.stats_cache_hit_count++;
+               _mail->transaction->stats_cache_hit_count++;
                if (mail->data.filter_stream != NULL)
                        i_stream_destroy(&mail->data.filter_stream);
                mail->data.filter_stream =
index 5de1307f6314607e1d852488774e7010ba6f482d..ebe578ab59bad22855326d8263e89ac29f5bd174 100644 (file)
@@ -50,7 +50,7 @@ int index_mail_cache_lookup_field(struct index_mail *mail, buffer_t *buf,
        ret = mail_cache_lookup_field(mail->mail.mail.transaction->cache_view,
                                      buf, mail->data.seq, field_idx);
        if (ret > 0)
-               mail->mail.stats_cache_hit_count++;
+               mail->mail.mail.transaction->stats_cache_hit_count++;
        return ret;
 }
 
@@ -830,12 +830,14 @@ int index_mail_init_stream(struct index_mail *mail,
                           struct message_size *body_size,
                           struct istream **stream_r)
 {
+       struct mail *_mail = &mail->mail.mail;
        struct index_mail_data *data = &mail->data;
        struct istream *input;
        int ret;
 
-       if (!data->initialized_wrapper_stream && mail->mail.stats_track) {
-               input = i_stream_create_mail_stats_counter(&mail->mail,
+       if (!data->initialized_wrapper_stream &&
+           _mail->transaction->stats_track) {
+               input = i_stream_create_mail_stats_counter(_mail->transaction,
                                                           data->stream);
                i_stream_unref(&data->stream);
                data->stream = input;
index 6e08958d7aaf1170d0ee27944f0904253ac083fd..8c675becc72adabd32b8bff9b30fa11dda190717 100644 (file)
@@ -1184,41 +1184,36 @@ int index_storage_search_deinit(struct mail_search_context *_ctx)
        array_free(&ctx->mail_ctx.results);
        array_free(&ctx->mail_ctx.module_contexts);
 
-       array_foreach_modifiable(&ctx->mails, mailp) {
-               struct index_mail *imail = (struct index_mail *)*mailp;
-
-               imail->search_mail = FALSE;
+       array_foreach_modifiable(&ctx->mails, mailp)
                mail_free(mailp);
-       }
        array_free(&ctx->mails);
        i_free(ctx);
        return ret;
 }
 
-static unsigned long long search_mail_get_cost(struct mail_private *mail)
+static unsigned long long
+search_get_cost(struct mailbox_transaction_context *trans)
 {
-       return mail->stats_open_lookup_count * SEARCH_COST_DENTRY +
-               mail->stats_stat_lookup_count * SEARCH_COST_DENTRY +
-               mail->stats_fstat_lookup_count * SEARCH_COST_ATTR +
-               mail->stats_cache_hit_count * SEARCH_COST_CACHE +
-               mail->stats_files_read_count * SEARCH_COST_FILES_READ +
-               (mail->stats_files_read_bytes/1024) * SEARCH_COST_KBYTE;
+       return trans->stats_open_lookup_count * SEARCH_COST_DENTRY +
+               trans->stats_stat_lookup_count * SEARCH_COST_DENTRY +
+               trans->stats_fstat_lookup_count * SEARCH_COST_ATTR +
+               trans->stats_cache_hit_count * SEARCH_COST_CACHE +
+               trans->stats_files_read_count * SEARCH_COST_FILES_READ +
+               (trans->stats_files_read_bytes/1024) * SEARCH_COST_KBYTE;
 }
 
 static int search_match_once(struct index_search_context *ctx)
 {
-       struct mail_private *mail_private =
-               (struct mail_private *)ctx->cur_mail;
        unsigned long long cost1, cost2;
        int ret;
 
-       cost1 = search_mail_get_cost(mail_private);
+       cost1 = search_get_cost(ctx->cur_mail->transaction);
        ret = mail_search_args_foreach(ctx->mail_ctx.args->args,
                                       search_cached_arg, ctx);
        if (ret < 0)
                ret = search_arg_match_text(ctx->mail_ctx.args->args, ctx);
 
-       cost2 = search_mail_get_cost(mail_private);
+       cost2 = search_get_cost(ctx->cur_mail->transaction);
        ctx->cost += cost2 - cost1;
        return ret;
 }
@@ -1471,7 +1466,7 @@ struct mail *index_search_get_mail(struct index_search_context *ctx)
                          ctx->mail_ctx.wanted_headers);
        imail = (struct index_mail *)mail;
        imail->search_mail = TRUE;
-       imail->mail.stats_track = TRUE;
+       ctx->mail_ctx.transaction->stats_track = TRUE;
 
        array_append(&ctx->mails, &mail, 1);
        return mail;
index 98f5534ee0ca5c474377e97bdd8e961acd883fc3..9b7b1db08d6c9df60b26d659872b426a74ae6cc9 100644 (file)
@@ -8,7 +8,7 @@
 struct mail_stats_istream {
        struct istream_private istream;
 
-       struct mail_private *mail;
+       struct mailbox_transaction_context *trans;
        unsigned int files_read_increased:1;
 };
 
@@ -24,10 +24,10 @@ i_stream_mail_stats_read_mail_stats(struct istream_private *stream)
 
        ret = i_stream_read_copy_from_parent(&stream->istream);
        if (ret > 0) {
-               mstream->mail->stats_files_read_bytes += ret;
+               mstream->trans->stats_files_read_bytes += ret;
                if (!mstream->files_read_increased) {
                        mstream->files_read_increased = TRUE;
-                       mstream->mail->stats_files_read_count++;
+                       mstream->trans->stats_files_read_count++;
                }
        }
        return ret;
@@ -47,13 +47,14 @@ i_stream_mail_stats_stat(struct istream_private *stream, bool exact)
        return i_stream_stat(stream->parent, exact);
 }
 
-struct istream *i_stream_create_mail_stats_counter(struct mail_private *mail,
-                                                  struct istream *input)
+struct istream *
+i_stream_create_mail_stats_counter(struct mailbox_transaction_context *trans,
+                                  struct istream *input)
 {
        struct mail_stats_istream *mstream;
 
        mstream = i_new(struct mail_stats_istream, 1);
-       mstream->mail = mail;
+       mstream->trans = trans;
        mstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
 
        mstream->istream.parent = input;
index 2b5e8356f91a7c10c44c8bc9fd14f423112a72a5..7052f41f91f445de1bfae726b3465ee58a8b4cb7 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef ISTREAM_MAIL_STATS_H
 #define ISTREAM_MAIL_STATS_H
 
-struct istream *i_stream_create_mail_stats_counter(struct mail_private *mail,
-                                                  struct istream *input);
+struct istream *
+i_stream_create_mail_stats_counter(struct mailbox_transaction_context *trans,
+                                  struct istream *input);
 
 #endif
index 49f4e20257fd5a8c3ac830676906781016a62d37..9920e412dda258e4c0e68682c18d46ebf4c7d796 100644 (file)
@@ -62,7 +62,6 @@ static struct istream *
 maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail,
                  bool *deleted_r)
 {
-       struct mail_private *p = (struct mail_private *)mail;
        struct istream *input;
        const char *path;
        struct maildir_open_context ctx;
@@ -72,7 +71,7 @@ maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail,
        ctx.fd = -1;
        ctx.path = NULL;
 
-       p->stats_open_lookup_count++;
+       mail->transaction->stats_open_lookup_count++;
        if (!mail->saving) {
                if (maildir_file_do(mbox, mail->uid, do_open, &ctx) < 0)
                        return NULL;
@@ -121,13 +120,13 @@ static int maildir_mail_stat(struct mail *mail, struct stat *st)
        }
 
        if (imail->data.stream != NULL) {
-               imail->mail.stats_fstat_lookup_count++;
+               mail->transaction->stats_fstat_lookup_count++;
                stp = i_stream_stat(imail->data.stream, FALSE);
                if (stp == NULL)
                        return -1;
                *st = *stp;
        } else if (!mail->saving) {
-               imail->mail.stats_stat_lookup_count++;
+               mail->transaction->stats_stat_lookup_count++;
                ret = maildir_file_do(mbox, mail->uid, do_stat, st);
                if (ret <= 0) {
                        if (ret == 0)
@@ -135,7 +134,7 @@ static int maildir_mail_stat(struct mail *mail, struct stat *st)
                        return -1;
                }
        } else {
-               imail->mail.stats_stat_lookup_count++;
+               mail->transaction->stats_stat_lookup_count++;
                path = maildir_save_file_get_path(mail->transaction, mail->seq);
                if (stat(path, st) < 0) {
                        mail_storage_set_critical(mail->box->storage,
index ddfe63b4925ac784a12c502bea0e4cb999ef7551..2b2dd0879af132c2f71a45e4a7f133bfdc2b4f0b 100644 (file)
 static int raw_mail_stat(struct mail *mail)
 {
        struct raw_mailbox *mbox = (struct raw_mailbox *)mail->box;
-       struct mail_private *p = (struct mail_private *)mail;
        const struct stat *st;
 
        if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
                return mail_set_aborted(mail);
 
-       p->stats_fstat_lookup_count++;
+       mail->transaction->stats_fstat_lookup_count++;
        st = i_stream_stat(mail->box->input, TRUE);
        if (st == NULL) {
                mail_storage_set_critical(mail->box->storage,
index b88ec67b25eedfaf41081ffc7cdd13dad0b1772c..400c6e599693bdfc5c081b2c76b934713b351320 100644 (file)
@@ -333,21 +333,6 @@ struct mail_private {
 
        pool_t pool;
        ARRAY_DEFINE(module_contexts, union mail_module_context *);
-
-       /* these statistics are never reset by mail-storage API: */
-
-       unsigned long stats_open_lookup_count;
-       unsigned long stats_stat_lookup_count;
-       unsigned long stats_fstat_lookup_count;
-       /* number of files we've opened and read */
-       unsigned long stats_files_read_count;
-       /* number of bytes we've had to read from files */
-       unsigned long long stats_files_read_bytes;
-       /* number of cache lookup hits */
-       unsigned long stats_cache_hit_count;
-
-       /* Set to TRUE to update stats_* fields */
-       unsigned int stats_track:1;
 };
 
 struct mailbox_list_context {
@@ -380,6 +365,21 @@ struct mailbox_transaction_context {
                     union mailbox_transaction_module_context *);
 
        struct mail_save_context *save_ctx;
+
+       /* these statistics are never reset by mail-storage API: */
+
+       unsigned long stats_open_lookup_count;
+       unsigned long stats_stat_lookup_count;
+       unsigned long stats_fstat_lookup_count;
+       /* number of files we've opened and read */
+       unsigned long stats_files_read_count;
+       /* number of bytes we've had to read from files */
+       unsigned long long stats_files_read_bytes;
+       /* number of cache lookup hits */
+       unsigned long stats_cache_hit_count;
+
+       /* Set to TRUE to update stats_* fields */
+       unsigned int stats_track:1;
 };
 
 union mail_search_module_context {