]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: saved-date doesn't need to be looked up until mail body is being read.
authorTimo Sirainen <tss@iki.fi>
Wed, 30 Apr 2014 03:08:46 +0000 (06:08 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 30 Apr 2014 03:08:46 +0000 (06:08 +0300)
This should improve the performance when the saved-date isn't already cached
or otherwise quickly accessible.

This change also makes dsync slightly incompatible with earlier versions.
When using dsync with an earlier version the saved-dates aren't synced. It
would be too much trouble to try to preserve full backwards compatibility,
especially because saved-date doesn't matter so much and isn't even visible
to IMAP clients.

src/doveadm/dsync/dsync-ibc-stream.c
src/doveadm/dsync/dsync-mail.c
src/doveadm/dsync/dsync-mail.h
src/doveadm/dsync/dsync-mailbox-export.c
src/doveadm/dsync/dsync-mailbox-import.c

index 65252d168147ba3eb3748c4d4571569c71124607..6b4b660b2ef9d1d1ceef49d096f16058f8870ee2 100644 (file)
@@ -109,7 +109,7 @@ static const struct {
        { .name = "mail_change",
          .chr = 'C',
          .required_keys = "type uid",
-         .optional_keys = "guid hdr_hash modseq pvt_modseq save_timestamp "
+         .optional_keys = "guid hdr_hash modseq pvt_modseq "
                "add_flags remove_flags final_flags "
                "keywords_reset keyword_changes"
        },
@@ -119,7 +119,7 @@ static const struct {
        },
        { .name = "mail",
          .chr = 'M',
-         .optional_keys = "guid uid pop3_uidl pop3_order received_date stream"
+         .optional_keys = "guid uid pop3_uidl pop3_order received_date saved_date stream"
        },
        { .name = "mailbox_cache_field",
          .chr = 'c',
@@ -1508,10 +1508,6 @@ dsync_ibc_stream_send_change(struct dsync_ibc *_ibc,
                dsync_serializer_encode_add(encoder, "pvt_modseq",
                                            dec2str(change->pvt_modseq));
        }
-       if (change->save_timestamp != 0) {
-               dsync_serializer_encode_add(encoder, "save_timestamp",
-                                           dec2str(change->save_timestamp));
-       }
        if (change->add_flags != 0) {
                dsync_serializer_encode_add(encoder, "add_flags",
                        t_strdup_printf("%x", change->add_flags));
@@ -1601,11 +1597,6 @@ dsync_ibc_stream_recv_change(struct dsync_ibc *_ibc,
                dsync_ibc_input_error(ibc, decoder, "Invalid pvt_modseq");
                return DSYNC_IBC_RECV_RET_TRYAGAIN;
        }
-       if (dsync_deserializer_decode_try(decoder, "save_timestamp", &value) &&
-           str_to_time(value, &change->save_timestamp) < 0) {
-               dsync_ibc_input_error(ibc, decoder, "Invalid save_timestamp");
-               return DSYNC_IBC_RECV_RET_TRYAGAIN;
-       }
 
        if (dsync_deserializer_decode_try(decoder, "add_flags", &value))
                change->add_flags = strtoul(value, NULL, 16);
@@ -1709,6 +1700,10 @@ dsync_ibc_stream_send_mail(struct dsync_ibc *_ibc,
                dsync_serializer_encode_add(encoder, "received_date",
                                            dec2str(mail->received_date));
        }
+       if (mail->saved_date != 0) {
+               dsync_serializer_encode_add(encoder, "saved_date",
+                                           dec2str(mail->saved_date));
+       }
        if (mail->input != NULL)
                dsync_serializer_encode_add(encoder, "stream", "");
 
@@ -1770,6 +1765,11 @@ dsync_ibc_stream_recv_mail(struct dsync_ibc *_ibc, struct dsync_mail **mail_r)
                dsync_ibc_input_error(ibc, decoder, "Invalid received_date");
                return DSYNC_IBC_RECV_RET_TRYAGAIN;
        }
+       if (dsync_deserializer_decode_try(decoder, "saved_date", &value) &&
+           str_to_time(value, &mail->saved_date) < 0) {
+               dsync_ibc_input_error(ibc, decoder, "Invalid saved_date");
+               return DSYNC_IBC_RECV_RET_TRYAGAIN;
+       }
        if (dsync_deserializer_decode_try(decoder, "stream", &value)) {
                mail->input = dsync_ibc_stream_input_stream(ibc);
                if (dsync_ibc_stream_read_mail_stream(ibc) <= 0) {
index 2cf52220c9d0d82c12cabc382dd8584236dbe836..5fb986f6a795137b3ae7ec2848384476f3d09cbf 100644 (file)
@@ -97,6 +97,10 @@ int dsync_mail_fill(struct mail *mail, struct dsync_mail *dmail_r,
                *error_field_r = "received-date";
                return -1;
        }
+       if (mail_get_save_date(mail, &dmail_r->saved_date) < 0) {
+               *error_field_r = "saved-date";
+               return -1;
+       }
        return 0;
 }
 
@@ -133,7 +137,6 @@ void dsync_mail_change_dup(pool_t pool, const struct dsync_mail_change *src,
        dest_r->hdr_hash = p_strdup(pool, src->hdr_hash);
        dest_r->modseq = src->modseq;
        dest_r->pvt_modseq = src->pvt_modseq;
-       dest_r->save_timestamp = src->save_timestamp;
 
        dest_r->add_flags = src->add_flags;
        dest_r->remove_flags = src->remove_flags;
index 4339030590abfd811c0159cc8a215a8465213d15..70ccd0c5234e4077dc1a6fa86eb44eccfc12aab7 100644 (file)
@@ -14,6 +14,7 @@ struct dsync_mail {
        const char *pop3_uidl;
        unsigned int pop3_order;
        time_t received_date;
+       time_t saved_date;
 
        /* Input stream containing the message text, or NULL if all instances
           of the message were already expunged from this mailbox. */
@@ -60,8 +61,6 @@ struct dsync_mail_change {
        /* Message's current private modseq (for private flags in
           shared mailboxes, otherwise 0) */
        uint64_t pvt_modseq;
-       /* Message's save timestamp (saves) */
-       time_t save_timestamp;
 
        /* List of flag/keyword changes: (saves, flag changes) */
 
index 9f1f11d5317737a0e5924b3e95f294a9a09657ef..31ce03c2fdf9b26528d5b51842db3bf051007c96 100644 (file)
@@ -270,24 +270,18 @@ search_add_save(struct dsync_mailbox_exporter *exporter, struct mail *mail)
 {
        struct dsync_mail_change *change;
        const char *guid, *hdr_hash;
-       time_t save_timestamp;
        int ret;
 
        /* update wanted fields in case we didn't already set them for the
           search */
-       mail_add_temp_wanted_fields(mail, MAIL_FETCH_GUID |
-                                   MAIL_FETCH_SAVE_DATE,
+       mail_add_temp_wanted_fields(mail, MAIL_FETCH_GUID,
                                    exporter->wanted_headers);
 
        /* If message is already expunged here, just skip it */
        if ((ret = exporter_get_guids(exporter, mail, &guid, &hdr_hash)) <= 0)
                return ret;
-       if (mail_get_save_date(mail, &save_timestamp) < 0)
-               return dsync_mail_error(exporter, mail, "save-date");
 
        change = export_save_change_get(exporter, mail->uid);
-       change->save_timestamp = save_timestamp;
-
        change->guid = *guid == '\0' ? "" :
                p_strdup(exporter->pool, guid);
        change->hdr_hash = p_strdup(exporter->pool, hdr_hash);
@@ -364,7 +358,7 @@ dsync_mailbox_export_search(struct dsync_mailbox_exporter *exporter)
        if (exporter->last_common_uid == 0) {
                /* we're syncing all mails, so we can request the wanted
                   fields for all the mails */
-               wanted_fields = MAIL_FETCH_GUID | MAIL_FETCH_SAVE_DATE;
+               wanted_fields = MAIL_FETCH_GUID;
                wanted_headers = exporter->wanted_headers;
        }
 
@@ -727,6 +721,7 @@ dsync_mailbox_export_body_search_init(struct dsync_mailbox_exporter *exporter)
                                    MAIL_FETCH_UIDL_BACKEND |
                                    MAIL_FETCH_POP3_ORDER |
                                    MAIL_FETCH_RECEIVED_DATE |
+                                   MAIL_FETCH_SAVE_DATE |
                                    MAIL_FETCH_STREAM_HEADER |
                                    MAIL_FETCH_STREAM_BODY, NULL);
        mail_search_args_unref(&search_args);
index 237eb49a0f2ccce107a30797ac63b6d24550a54d..d3fca249f73f4a1a78a6e8efb506e7c81f31306e 100644 (file)
@@ -1872,7 +1872,6 @@ dsync_mailbox_save_set_metadata(struct dsync_mailbox_importer *importer,
        if (keywords != NULL)
                mailbox_keywords_unref(&keywords);
 
-       mailbox_save_set_save_date(save_ctx, change->save_timestamp);
        if (change->modseq > 1) {
                (void)mailbox_enable(importer->box, MAILBOX_FEATURE_CONDSTORE);
                mailbox_save_set_min_modseq(save_ctx, change->modseq);
@@ -1915,6 +1914,8 @@ dsync_mailbox_save_init(struct dsync_mailbox_importer *importer,
        mailbox_save_set_uid(save_ctx, newmail->final_uid);
        if (*mail->guid != '\0')
                mailbox_save_set_guid(save_ctx, mail->guid);
+       if (mail->saved_date != 0)
+               mailbox_save_set_save_date(save_ctx, mail->saved_date);
        dsync_mailbox_save_set_metadata(importer, save_ctx, newmail->change);
        if (mail->pop3_uidl != NULL && *mail->pop3_uidl != '\0')
                mailbox_save_set_pop3_uidl(save_ctx, mail->pop3_uidl);