]> 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, 28 Jun 2023 12:26:18 +0000 (14:26 +0200)
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 513db02c099760e04b49c40ff058ad27f3532598..eaace6fc1f5359d69c01eabf8f352187a4af1e99 100644 (file)
@@ -77,12 +77,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);
@@ -110,28 +123,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;
@@ -180,7 +171,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) {