emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Lele Gaifax <lele@metapensiero.it>
Cc: emacs-orgmode@gnu.org
Subject: Re: org-persist cache for remote files
Date: Sun, 19 Dec 2021 17:56:26 +0800	[thread overview]
Message-ID: <87bl1csyt1.fsf@localhost> (raw)
In-Reply-To: <87k0g2ylsx.fsf@metapensiero.it>

[-- Attachment #1: Type: text/plain, Size: 214 bytes --]

Lele Gaifax <lele@metapensiero.it> writes:

> I couldn't test yet, but I saw a couple of other glitches, sorry for not
> noticing first.

Thanks for the proof reading.
I updated the patch accordingly.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-persist.el-Customise-persistence-of-data-for-rem.patch --]
[-- Type: text/x-diff, Size: 3579 bytes --]

From 557e7cec6dd22b09468b82650feed2020f97d781 Mon Sep 17 00:00:00 2001
Message-Id: <557e7cec6dd22b09468b82650feed2020f97d781.1639907677.git.yantar92@gmail.com>
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
 files

* 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 prompts
while garbage collecting the cache: remote files may require server
login.
(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..8e8ecc196 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 persistent data associated with
+remote files.  When `t', always keep the data.  When a number, keep up
+to that number persistent values for remote files.  When
+`check-existence', contact remote server containing the file and only
+keep the data when the file exists on the server.
+
+Note that setting value to `check-existence' will require logging in
+to remote servers.  Emacs may show multiple password prompts."
+  :group 'org-persist
+  :type '(choice (const :tag "Never" nil)
+                 (const :tag "Always" t)
+                 (number :tag "Up to 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)
-- 
2.32.0


  parent reply	other threads:[~2021-12-19  9:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20  5:46 org-persist Colin Baxter 😺
2021-10-20  6:23 ` org-persist Ihor Radchenko
2021-10-20  6:37   ` org-persist Colin Baxter 😺
2021-10-20  6:55     ` org-persist Ihor Radchenko
2021-10-20  9:12       ` org-persist Colin Baxter 😺
2021-10-20  9:41         ` org-persist Ihor Radchenko
2021-10-20 11:45           ` org-persist Colin Baxter 😺
2021-10-20 12:44             ` org-persist Ihor Radchenko
2021-12-17 21:05               ` org-persist Lele Gaifax
2021-12-18  4:22                 ` org-persist cache for remote files (was: org-persist) Ihor Radchenko
2021-12-18  6:46                   ` org-persist cache for remote files Lele Gaifax
2021-12-18 14:21                     ` Ihor Radchenko
2021-12-18 14:36                       ` Lele Gaifax
2021-12-18 14:47                         ` Ihor Radchenko
2021-12-18 15:28                           ` Lele Gaifax
2021-12-18 18:18                             ` Lele Gaifax
2021-12-19  9:56                             ` Ihor Radchenko [this message]
2021-12-21  8:11                               ` Lele Gaifax
2021-12-21  9:03                                 ` Ihor Radchenko
2021-10-20 20:25       ` org-persist Samuel Wales
2021-10-21  2:18         ` org-persist Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bl1csyt1.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=lele@metapensiero.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).