better handle maildir cache

- get an updated maildir list after indexing
- add mu4e-added items to the list opportunistically

Remove mu4e-clear-caches / mu4e-cache-maildir-list to mu4e-obsolete.el

Fixes #2537.
This commit is contained in:
Dirk-Jan C. Binnema 2023-08-19 19:41:56 +03:00
parent 15f08488d3
commit f73aad2b41
6 changed files with 40 additions and 35 deletions

View File

@ -81,8 +81,10 @@
If and how much this helps, depends on your setup, see the
=mu4e-mu-allow-temp-file= docstring for details on how to determine this.
- Jumping to the 'jo' /other/ Maildirs used to quite slow the first time, but
this now done on the server side, making it much faster.
- Maildir lists are now generated server-side; so e.g. jumping to the 'jo'
/other/ Maildirs used to be quite slow the first time.
~mu4e-cache-maildir-list~ is obsolete / non-functional now.
- after retrieving mail (~mu4e-update-mail-and-index~), save the output of the
retrieval command in a buffer =*mu4e-last-update*=, = which can be useful

View File

@ -886,15 +886,20 @@ Server::Private::mkdir_handler(const Command& cmd)
const auto path{cmd.string_arg(":path").value_or("<error>")};
const auto update{cmd.boolean_arg(":update")};
if (path.find(store().root_maildir()) != 0)
throw Error{Error::Code::File, "maildir is not below root-maildir"};
if (auto&& res = maildir_mkdir(path, 0755, false); !res)
throw res.error();
/* mu4e does a lot of opportunistic 'mkdir', only send it updates when
* requested */
if (update)
output_sexp(Sexp().put_props(":info", "mkdir",
":message",
mu_format("{} has been created", path)));
if (!update)
return;
output_sexp(Sexp().put_props(":info", "mkdir",
":message",
mu_format("{} has been created", path)));
}
void

View File

@ -162,17 +162,6 @@ mime-type are nil."
(defvar mu4e-maildir-list nil
"Cached list of maildirs.")
(defcustom mu4e-cache-maildir-list t
"Whether to cache the list of maildirs.
Set it to t if you find that generating the list on the fly is
too slow.
If you do so, you can set `mu4e-maildir-list' to nil to force
regenerating the cache the next time `mu4e-get-maildirs' gets
called."
:type 'boolean
:group 'mu4e-folders)
(defun mu4e-maildir-shortcuts ()
"Get `mu4e-maildir-shortcuts' in the (new) format.
@ -204,19 +193,19 @@ the result."
(or val (mu4e-error "%S evaluates to nil" foldervar)))))
(defun mu4e-get-drafts-folder (&optional msg)
"Get the drafts folder, optionallly based on MSG.
"Get the drafts folder, optionally based on MSG.
See `mu4e-drafts-folder'." (mu4e--get-folder 'mu4e-drafts-folder msg))
(defun mu4e-get-refile-folder (&optional msg)
"Get the folder for refiling, optionallly based on MSG.
"Get the folder for refiling, optionally based on MSG.
See `mu4e-refile-folder'." (mu4e--get-folder 'mu4e-refile-folder msg))
(defun mu4e-get-sent-folder (&optional msg)
"Get the sent folder, optionallly based on MSG.
"Get the sent folder, optionally based on MSG.
See `mu4e-sent-folder'." (mu4e--get-folder 'mu4e-sent-folder msg))
(defun mu4e-get-trash-folder (&optional msg)
"Get the trash folder, optionallly based on MSG.
"Get the trash folder, optionally based on MSG.
See `mu4e-trash-folder'." (mu4e--get-folder 'mu4e-trash-folder msg))
;;; Maildirs
@ -237,11 +226,9 @@ to create it; otherwise return nil."
(let ((seems-to-exist (file-directory-p dir)))
(when (or seems-to-exist
(yes-or-no-p (mu4e-format "%s does not exist yet. Create now?" dir)))
;; even when the maildir already seems to exist,
;; call mkdir for a deeper check. However only get an update
;; when the maildir is totally new.
;; even when the maildir already seems to exist, call mkdir for a deeper
;; check. However only get an update when the maildir is totally new.
(mu4e--server-mkdir dir (not seems-to-exist))
(setq mu4e-maildir-list nil) ;; clear cache
t)))
(defun mu4e-get-maildirs ()

View File

@ -224,5 +224,11 @@
(define-obsolete-function-alias 'mu4e-quote-for-modeline
'mu4e--modeline-quote-and-truncate "1.9.16")
;; mu4e-folder
(make-obsolete-variable 'mu4e-cache-maildir-list "No longer used" "1.11.15")
;; mu4e.
(make-obsolete 'mu4e-clear-caches "No longer used" "1.11.15")
(provide 'mu4e-obsolete)
;;; mu4e-obsolete.el ends here

View File

@ -643,7 +643,13 @@ the directory time stamp."
(defun mu4e--server-mkdir (path &optional update)
"Create a new maildir-directory at filesystem PATH.
When UPDATE is non-nil, send a update when completed."
When UPDATE is non-nil, send a update when completed.
PATH must be below the root-maildir."
;; handle maildir cache
(if (not (string-prefix-p (mu4e-root-maildir) path))
(mu4e-error "Cannot create maildir outside root-maildir")
(add-to-list 'mu4e-maildir-list ;; update cache
(substring path (length (mu4e-root-maildir)))))
(mu4e--server-call-mu `(mkdir
:path ,path
:update ,(or update nil))))

View File

@ -160,7 +160,12 @@ Otherwise, check requirements, then start mu4e. When successful, invoke
(when mu4e--update-timer
(cancel-timer mu4e--update-timer)
(setq mu4e--update-timer nil))
(mu4e-clear-caches)
(setq ;; clear some caches
mu4e-maildir-list nil
mu4e--contacts-set nil
mu4e--contacts-tstamp "0")
(remove-hook 'mu4e-query-items-updated-hook #'mu4e--main-redraw)
(remove-hook 'mu4e-query-items-updated-hook #'mu4e--modeline-update)
(remove-hook 'mu4e-query-items-updated-hook #'mu4e--notification)
@ -229,7 +234,8 @@ Otherwise, check requirements, then start mu4e. When successful, invoke
mu4e-message-changed-hook)
(unless (and (not (string= mu4e--contacts-tstamp "0"))
(zerop (plist-get info :updated)))
(mu4e--request-contacts-maybe))
(mu4e--request-contacts-maybe)
(mu4e--server-data 'maildirs)) ;; update maildir list
(mu4e--main-redraw))))
((plist-get info :message)
(mu4e-index-message "%s" (plist-get info :message))))))
@ -253,13 +259,6 @@ chance."
(mu4e-setq-if-nil mu4e-pong-func #'mu4e--default-handler)
(mu4e-setq-if-nil mu4e-queries-func #'mu4e--query-items-queries-handler))
(defun mu4e-clear-caches ()
"Clear any cached resources."
(setq
mu4e-maildir-list nil
mu4e--contacts-set nil
mu4e--contacts-tstamp "0"))
;;;
(provide 'mu4e)