From: Timo Sirainen Date: Tue, 20 Jun 2023 15:58:13 +0000 (+0300) Subject: mdbox: Optimize mail_temp_scan_interval storage/ scanning X-Git-Tag: 2.4.0~2679 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88eee28fd86d619b26ce6aebadca5b18e748dc6f;p=thirdparty%2Fdovecot%2Fcore.git mdbox: Optimize mail_temp_scan_interval storage/ scanning Use the generic dbox scanning code, which avoids stat()ing the directory by keeping the timestamp in index header. Also do the scanning while at session deinit instead of startup, so the latency isn't visible to clients. --- diff --git a/src/lib-storage/index/dbox-multi/mdbox-map.c b/src/lib-storage/index/dbox-multi/mdbox-map.c index 309a17ba07..bb3fb09030 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.c +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c @@ -80,12 +80,25 @@ mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list) return map; } +static void mdbox_map_deinit_cleanup(struct mdbox_map *map) +{ + if (map->view == NULL) + return; + + const struct mail_index_header *hdr = + mail_index_get_header(map->view); + if (dbox_mailbox_list_cleanup(map->root_list, map->path, + hdr->last_temp_file_scan) > 0) + index_mailbox_view_update_last_temp_file_scan(map->view); +} + void mdbox_map_deinit(struct mdbox_map **_map) { struct mdbox_map *map = *_map; *_map = NULL; + mdbox_map_deinit_cleanup(map); if (map->view != NULL) { mail_index_view_close(&map->view); mail_index_close(map->index); @@ -114,28 +127,6 @@ static int mdbox_map_mkdir_storage(struct mdbox_map *map) return 0; } -static void mdbox_map_cleanup(struct mdbox_map *map) -{ - unsigned int interval = - MAP_STORAGE(map)->set->mail_temp_scan_interval; - struct stat st; - - if (stat(map->path, &st) < 0) - return; - - /* check once in a while if there are temp files to clean up */ - if (interval == 0) { - /* disabled */ - } else if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) { - /* there haven't been any changes to this directory since we - last checked it. */ - } else if (st.st_atime < ioloop_time - (time_t)interval) { - /* time to scan */ - (void)unlink_old_files(map->path, DBOX_TEMP_FILE_PREFIX, - ioloop_time - DBOX_TMP_DELETE_SECS); - } -} - static int mdbox_map_open_internal(struct mdbox_map *map, bool create_missing) { enum mail_index_open_flags open_flags; @@ -184,7 +175,6 @@ static int mdbox_map_open_internal(struct mdbox_map *map, bool create_missing) } map->view = mail_index_view_open(map->index); - mdbox_map_cleanup(map); if (mail_index_get_header(map->view)->uid_validity == 0) { if (mdbox_map_generate_uid_validity(map) < 0) {