[dovecot-cvs] dovecot: Update day headers while committing appends.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jun 13 23:28:30 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/c3e32c3fb2bf
changeset: 5729:c3e32c3fb2bf
user: Timo Sirainen <tss at iki.fi>
date: Wed Jun 13 23:28:23 2007 +0300
description:
Update day headers while committing appends.
diffstat:
2 files changed, 53 insertions(+), 42 deletions(-)
src/lib-index/mail-index-sync-update.c | 41 ------------------------
src/lib-index/mail-index-transaction.c | 54 +++++++++++++++++++++++++++++++-
diffs (143 lines):
diff -r 7aab5d99fb45 -r c3e32c3fb2bf src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c Wed Jun 13 23:00:58 2007 +0300
+++ b/src/lib-index/mail-index-sync-update.c Wed Jun 13 23:28:23 2007 +0300
@@ -477,44 +477,6 @@ static int sync_header_update(const stru
u + 1, sizeof(map->hdr) - u->offset);
}
return 1;
-}
-
-static void
-mail_index_update_day_headers(struct mail_index_header *hdr, uint32_t uid)
-{
- // FIXME: move as header updates to transaction committing
- const int max_days =
- sizeof(hdr->day_first_uid) / sizeof(hdr->day_first_uid[0]);
- struct tm tm;
- time_t stamp;
- int i, days;
-
- /* get beginning of today */
- tm = *localtime(&ioloop_time);
- tm.tm_hour = 0;
- tm.tm_min = 0;
- tm.tm_sec = 0;
- stamp = mktime(&tm);
- if (stamp == (time_t)-1)
- i_panic("mktime(today) failed");
-
- if ((time_t)hdr->day_stamp >= stamp)
- return;
-
- /* get number of days since last message */
- days = (stamp - hdr->day_stamp) / (3600*24);
- if (days > max_days)
- days = max_days;
-
- /* @UNSAFE: move days forward and fill the missing days with old
- day_first_uid[0]. */
- memcpy(hdr->day_first_uid + days,
- hdr->day_first_uid, max_days - days);
- for (i = 1; i < days; i++)
- hdr->day_first_uid[i] = hdr->day_first_uid[0];
-
- hdr->day_stamp = stamp;
- hdr->day_first_uid[0] = uid;
}
int mail_index_sync_record(struct mail_index_sync_map_ctx *ctx,
@@ -900,9 +862,6 @@ int mail_index_sync_map(struct mail_inde
map->hdr.log_file_mailbox_offset =
index->log->head->mailbox_sync_max_offset;
- /*FIXME: if (first_append_uid != 0)
- mail_index_update_day_headers(&map->hdr, first_append_uid);*/
-
if (map->write_base_header) {
i_assert(MAIL_INDEX_MAP_IS_IN_MEMORY(map));
buffer_write(map->hdr_copy_buf, 0, &map->hdr, sizeof(map->hdr));
diff -r 7aab5d99fb45 -r c3e32c3fb2bf src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c Wed Jun 13 23:00:58 2007 +0300
+++ b/src/lib-index/mail-index-transaction.c Wed Jun 13 23:28:23 2007 +0300
@@ -5,6 +5,7 @@
UIDs. This is because we're able to compress sequence ranges better. */
#include "lib.h"
+#include "ioloop.h"
#include "array.h"
#include "seq-range-array.h"
#include "mail-index-view-private.h"
@@ -14,6 +15,7 @@
#include <stddef.h>
#include <stdlib.h>
+#include <time.h>
void (*hook_mail_index_transaction_created)
(struct mail_index_transaction *t) = NULL;
@@ -289,6 +291,53 @@ static int uid_map_cmp(const void *p1, c
(m1->uid > m2->uid ? 1 : 0);
}
+static void
+mail_index_update_day_headers(struct mail_index_transaction *t)
+{
+ struct mail_index_header hdr;
+ const struct mail_index_record *rec;
+ const int max_days =
+ sizeof(hdr.day_first_uid) / sizeof(hdr.day_first_uid[0]);
+ struct tm tm;
+ time_t stamp;
+ int i, days;
+
+ hdr = *mail_index_get_header(t->view);
+ rec = array_idx(&t->appends, 0);
+
+ /* get beginning of today */
+ tm = *localtime(&ioloop_time);
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ stamp = mktime(&tm);
+ i_assert(stamp != (time_t)-1);
+
+ if ((time_t)hdr.day_stamp >= stamp)
+ return;
+
+ /* get number of days since last message */
+ days = (stamp - hdr.day_stamp) / (3600*24);
+ if (days > max_days)
+ days = max_days;
+
+ /* @UNSAFE: move days forward and fill the missing days with old
+ day_first_uid[0]. */
+ memcpy(hdr.day_first_uid + days, hdr.day_first_uid, max_days - days);
+ for (i = 1; i < days; i++)
+ hdr.day_first_uid[i] = hdr.day_first_uid[0];
+
+ hdr.day_stamp = stamp;
+ hdr.day_first_uid[0] = rec->uid;
+
+ mail_index_update_header(t,
+ offsetof(struct mail_index_header, day_stamp),
+ &hdr.day_stamp, sizeof(hdr.day_stamp), FALSE);
+ mail_index_update_header(t,
+ offsetof(struct mail_index_header, day_first_uid),
+ hdr.day_first_uid, sizeof(hdr.day_first_uid), FALSE);
+}
+
void mail_index_transaction_sort_appends(struct mail_index_transaction *t)
{
struct mail_index_record *recs, *sorted_recs;
@@ -380,7 +429,10 @@ static int _mail_index_transaction_commi
t->cache_trans_ctx = NULL;
}
- mail_index_transaction_sort_appends(t);
+ if (array_is_created(&t->appends)) {
+ mail_index_transaction_sort_appends(t);
+ mail_index_update_day_headers(t);
+ }
if (mail_index_transaction_convert_to_uids(t) < 0)
ret = -1;
More information about the dovecot-cvs
mailing list