[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: org-persist cache for remote files

From: Ihor Radchenko
Subject: Re: org-persist cache for remote files
Date: Sat, 18 Dec 2021 22:47:05 +0800

Lele Gaifax <lele@metapensiero.it> writes:

> In the meanwhile, here below some notes:

Thanks! See the updated patch.


>From 92878fab54c26800562409f3c686f065b7523a61 Mon Sep 17 00:00:00 2001
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sat, 18 Dec 2021 22:14:24 +0800
Subject: [PATCH] org-persist.el: Customise persistence of data for remote

* lisp/org-persist.el (org-persist-remote-files): New defcustom
defining strategy for persisting data associated with remote files.
Separate strategy is necessary to avoid unexpected password promtps
while garbage collecting the cache: remote files may require server
(org-persist-gc): Decide whether to store remote file data according
to `org-persist-remote-files'.

Reported in https://list.orgmode.org/87bl1eilt6.fsf@localhost/T/#u
 lisp/org-persist.el | 42 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index 90f9a3bc9..4c0673c72 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -57,6 +57,23 @@ (defcustom org-persist-directory (expand-file-name
   :group 'org-persist
   :type 'directory)
+(defcustom org-persist-remote-files 100
+  "Whether to keep persistent data for remote files.
+When this variable is nil, never save persitent data associated with
+remote files.  When `t', always keep the data.  When
+`check-existence', contact remote server containing the file and only
+keep the data when the file exists on the server. When a number, keep
+up to that number persistent values for remote files.
+Note that the last option `check-existence' may cause Emacs to show
+password prompts to log in."
+  :group 'org-persist
+  :type '(choice (const :tag "Never" nil)
+                 (const :tag "Always" t)
+                 (number :tag "Keep note more than X files")
+                 (const :tag "Check if exist on remote" 'check-existence)))
 (defvar org-persist-index-file "index"
   "File name used to store the data index.")
@@ -287,15 +304,26 @@ (defun org-persist-read-all-buffer ()
 (defun org-persist-gc ()
   "Remove stored data for not existing files or unregistered variables."
-  (let (new-index)
+  (let (new-index (remote-files-num 0))
     (dolist (index org-persist--index)
-      (let ((file (plist-get index :path))
-            (persist-file (when (plist-get index :persist-file)
-                            (org-file-name-concat
-                             org-persist-directory
-                             (plist-get index :persist-file)))))
+      (let* ((file (plist-get index :path))
+             (file-remote (when file (file-remote-p file)))
+             (persist-file (when (plist-get index :persist-file)
+                             (org-file-name-concat
+                              org-persist-directory
+                              (plist-get index :persist-file)))))
         (when (and file persist-file)
-          (if (file-exists-p file)
+          (when (and file-remote persist-file)
+            (cl-incf remote-files-num))
+          (if (if (not file-remote)
+                  (file-exists-p file)
+                (pcase org-persist-remote-files
+                  ('t t)
+                  ('check-existence
+                   (file-exists-p file))
+                  ((pred #'numberp)
+                   (<= org-persist-remote-files remote-files-num))
+                  (_ nil)))
               (push index new-index)
             (when (file-exists-p persist-file)
               (delete-file persist-file)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]