Fix: (--value-at) Clear value cache when buffer changes

Fixes #59.  Thanks to Daniel Hubmann (@hubisan) for reporting.
This commit is contained in:
Adam Porter 2019-11-24 05:43:21 -06:00
parent 02159a831a
commit a1851ed0eb
2 changed files with 21 additions and 1 deletions

View file

@ -470,7 +470,8 @@ Values compared with `equal'."
buffer-unmodified-p (eq (buffer-modified-tick) modified-tick))
(unless (and buffer-cache buffer-unmodified-p)
;; Buffer-local node cache empty or invalid: make new one.
(setf position-cache (make-hash-table))
(setf position-cache (make-hash-table)
value-cache (gethash position position-cache))
(puthash (current-buffer)
(cons (buffer-modified-tick) position-cache)
org-ql-node-value-cache))

View file

@ -142,6 +142,25 @@ RESULTS should be a list of strings as returned by
(cl-loop while (re-search-forward org-heading-regexp nil t)
sum 1)))))
(describe "Caching"
(it "Clears value cache after buffer changes"
;; See <https://github.com/alphapapa/org-ql/issues/59>.
(with-temp-buffer
(org-mode)
(insert "* Heading 1
* Heading 2")
;; FIXME: `--value-at' does not actually move point, so we do it here.
(goto-char (point-min))
(expect (org-ql--value-at (point-min) #'org-get-heading)
:to-equal "Heading 1")
(erase-buffer)
;; FIXME: See above.
(insert "* Heading 2")
(goto-char (point-min))
(org-ql--value-at (point-min) #'point)
(expect (org-ql--value-at (point-min) #'org-get-heading)
:to-equal "Heading 2"))))
(describe "Query functions/macros"
(it "org-ql"