emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Bug: fragile org refile cache
@ 2021-04-28 16:09 Maxim Nikulin
  2021-04-29  0:50 ` Samuel Wales
  0 siblings, 1 reply; 18+ messages in thread
From: Maxim Nikulin @ 2021-04-28 16:09 UTC (permalink / raw)
  To: emacs-orgmode

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

Reviewing my attempt to speedup collecting of refile targets
https://orgmode.org/list/s209r8$16en$1@ciao.gmane.io/
I have realized that refile cache is unreliable.

With specific customization, cache content and thus refile targets 
depend on the function called first: `org-refile' ([C-u] C-c C-w) or 
`org-goto' (C-u C-c C-w).

I decided to try to provide minimal example and steps to reproduce in 
the form of a test marked as expected failure.

Certainly cache should be enabled
     (org-refile-use-cache t)
`org-refile-targets' should have (nil . (:maxlevel . 5)) for the 
affected buffer. The value of the following setting is intentionally set 
to alternative value in comparison to `org-goto' code
     (org-refile-use-outline-path nil)
To see the issue interactively, you likely should set
     (org-outline-path-complete-in-steps nil)

Clean cache (C-u C-u C-u C-c C-w) and try jumping using C-u C-c C-w and 
C-u C-c C-j in various order. Use TAB completion to see targets.

To make difference more apparent, define 
`org-refile-target-verify-function' to filter-out some headings.

My expectation that each command has list of targets formatted 
accordingly to user setting or `org-goto' internal overrides. Actually 
lists of target are the same since they share cache entry.

I suppose, cache keys should include values of all parameters affecting 
filtering and formatting, not only regexp for heading selection.

However I have no idea how to derive some value suitable for cache key 
from `org-refile-target-verify-function'.

[-- Attachment #2: 0001-testing-lisp-test-org.el-Refile-cache-failure.patch --]
[-- Type: text/x-patch, Size: 2431 bytes --]

From d23b10d658539a4646ef015ac2660e1f8c8e7e1b Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Wed, 28 Apr 2021 22:30:04 +0700
Subject: [PATCH] testing/lisp/test-org.el: Refile cache failure

testing/lisp/test-org.el (test-org/org-refile-cache): Add expected
failure for cache content discrepancy when it is populated
by `org-refile' or by `org-goto' (C-u C-c C-j).

Usage of just regexp for heading filtering as cache key is unreliable
since other settings affects selected entries
(`org-refile-target-verify-function') or content of entries
(`org-refile-use-outline-path').  However most of users have no chance
to notice collision since they do not call both functions
interchangeably or have `org-refile-targets' different from
the value in `org-goto' code.
---
 testing/lisp/test-org.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 9f0ede1b9..f44cd76a6 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -6394,6 +6394,30 @@ Paragraph<point>"
 	    (org-refile-targets `((nil :level . 1))))
        (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
 
+(ert-deftest test-org/org-refile-cache ()
+  "Demostrate a cache conflict of `org-goto' and `org-refile'.
+
+Notice that `org-refile-target-verify-function' can cause more severe
+divergence of cache content generated by these functions."
+  :expected-result :failed
+  (org-test-with-temp-text "* H1\n** H2\n"
+    (let ((org-refile-use-cache t)
+          ;; Regexp serves as cache key, so targets should be the same
+          ;; as in `org-goto' code.
+          (org-refile-targets '((nil . (:maxlevel . 5))))
+          ;; This value is opposite to the one in `org-goto' code.
+          (org-refile-use-outline-path nil)
+          (targets-refile))
+      ;; If jumping using `org-refile' (C-u C-c C-w)...
+      (setq targets-refile (mapcar #'car (org-refile-get-targets)))
+      (org-refile-cache-clear)
+      ;; Tune settings to simulate `org-goto' (C-u C-c C-j).
+      (let ((org-refile-use-outline-path t))
+        ;; Value is discarded, call just to populate the cache.
+        (org-refile-get-targets))
+      ;; Targets got by `org-refile'.
+      (let ((targets-goto (mapcar #'car (org-refile-get-targets))))
+        (should (equal targets-refile targets-goto))))))
 
 \f
 ;;; Sparse trees
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-05-05  0:50 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-28 16:09 [PATCH] Bug: fragile org refile cache Maxim Nikulin
2021-04-29  0:50 ` Samuel Wales
2021-04-29  1:29   ` Ihor Radchenko
2021-04-29  1:34     ` Samuel Wales
2021-04-29 12:45       ` Maxim Nikulin
2021-04-29 14:12         ` Ihor Radchenko
2021-04-29 15:04           ` Maxim Nikulin
2021-04-29 16:08             ` Ihor Radchenko
2021-04-29 16:51               ` Maxim Nikulin
2021-04-30 16:56               ` Maxim Nikulin
2021-05-01 14:48               ` Maxim Nikulin
2021-05-02  6:59                 ` Ihor Radchenko
2021-05-04 16:55                   ` Maxim Nikulin
2021-05-05  0:53                     ` Ihor Radchenko
2021-04-29 13:30       ` Ihor Radchenko
2021-04-29 19:17         ` Tim Cross
2021-04-29 22:43           ` Samuel Wales
2021-05-02  7:03           ` Ihor Radchenko

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).