]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Optimize mail_temp_scan_interval storage/ scanning
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 20 Jun 2023 15:58:13 +0000 (18:58 +0300)
committermarkus.valentin <markus.valentin@open-xchange.com>
Wed, 21 Jun 2023 12:46:57 +0000 (12:46 +0000)
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.

src/lib-storage/index/dbox-multi/mdbox-map.c

index 309a17ba07c25d813095a79bc9be62ed5ae4d950..bb3fb090302a7eaa7cda69331dc32be7df9c622e 100644 (file)
@@ -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) {