From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6OeoMSWLiWDHtwAAgWs5BA (envelope-from ) for ; Wed, 28 Apr 2021 18:19:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GP4+LSWLiWBQQQAA1q6Kng (envelope-from ) for ; Wed, 28 Apr 2021 16:19:49 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 18CDF9885 for ; Wed, 28 Apr 2021 18:19:49 +0200 (CEST) Received: from localhost ([::1]:56934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbmuh-00012x-Ky for larch@yhetil.org; Wed, 28 Apr 2021 12:19:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbmlL-0001DU-Pd for emacs-orgmode@gnu.org; Wed, 28 Apr 2021 12:10:07 -0400 Received: from ciao.gmane.io ([116.202.254.214]:44544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbmlJ-0003tY-TJ for emacs-orgmode@gnu.org; Wed, 28 Apr 2021 12:10:07 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lbmlH-000Abq-RW for emacs-orgmode@gnu.org; Wed, 28 Apr 2021 18:10:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin Subject: [PATCH] Bug: fragile org refile cache Date: Wed, 28 Apr 2021 23:09:57 +0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------E51137339C6E8B3B71245F54" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 X-Mozilla-News-Host: news://news.gmane.io:119 Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619626789; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=ArHiO1iT82PtTgroCPP4mHO9t/Pr47SuUUhu7IekWFo=; b=BoJKU6qA/z2wt7IWjd+WMLqF2FVNNAtmWNPu70mGVxB8mhnGSTmN7/md6W0TUqk6sSCVKp tDMOiCsegEMk9OSXKZy6j2uGnOF33c+s2thqjcMhEFqelVrnqfCE+MMQy8ZB538U6udOfv FNwsIMm6+MnTlRp3R922Nh2f1Hy3su15L+q2xatdEmv3a7BUWzaXXgydeWBTgng07kZtCW /OXJR2LRD/7ozyndu+e0cYGZ0+T+QdFP/fZh9BbSlc/qeniTZB9X8j3dfq1qD2Uerua6WI iQ+frgu0B13KPEy3nA+oADs8uhgHDqe56KE0tIQhYkyESJzOvKKBRwUSqcF19w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619626789; a=rsa-sha256; cv=none; b=tdtrJ3DedFXRIpDRfTOlkzvv1SHbv911TK8fwuERWzpvUPKtofye4L8qKoXD2C13Ox/nIR RvbzZziFoPjna0sxyQZwNP1tYenNL2ex7KVQ9vRa52AcDFTdbgV9SZb0dmu77m0htHkbfS CvXszXi+6x8d1o7fcdn6sD/2se1KSIX84uH2VJHuAqMkalaW+1QO/4MJWYeu0EbNODA/2O LCjPVHk8hld7PG0zPYylT5AeOXMEVkWPxvyZkH6dhQ63zkwEuW8OH4iHeswKbnjXMtQK85 AnGs89zQokGPB2z7kMc2JBGu/di9E3Gu7khXpLU70wlpdit9JCFZvf0jdZla5g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.75 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 18CDF9885 X-Spam-Score: -1.75 X-Migadu-Scanner: scn0.migadu.com X-TUID: c1ayRSuIg3Un This is a multi-part message in MIME format. --------------E51137339C6E8B3B71245F54 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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'. --------------E51137339C6E8B3B71245F54 Content-Type: text/x-patch; charset=UTF-8; name="0001-testing-lisp-test-org.el-Refile-cache-failure.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-testing-lisp-test-org.el-Refile-cache-failure.patch" >From d23b10d658539a4646ef015ac2660e1f8c8e7e1b Mon Sep 17 00:00:00 2001 From: Max Nikulin 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" (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)))))) ;;; Sparse trees -- 2.25.1 --------------E51137339C6E8B3B71245F54--