Skip to content

Commit

Permalink
Add cache-build step
Browse files Browse the repository at this point in the history
  • Loading branch information
l3kn committed Mar 18, 2024
1 parent 8ed2d3d commit 00747df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 12 additions & 1 deletion org-fc-cache.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
(make-hash-table :test #'equal)
"Cache mapping filenames to card lists.")

(defun org-fc-cache-build ()
"Build initial cache."
(let* ((hashes (org-fc-cache-hashes org-fc-directories))
(table (make-hash-table :test #'equal)))
(dolist (entry (org-fc-awk-index org-fc-directories))
(let* ((path (oref entry path))
(hash (gethash path hashes)))
(setf (oref entry hash) hash)
(puthash path entry table)))
(setq org-fc-cache table)))

(defun org-fc-cache-update ()
"Make sure the cache is up to date."
(let* ((hashes (org-fc-cache-hashes org-fc-directories))
Expand Down Expand Up @@ -101,7 +112,7 @@ as its input."
"Enable org-fc-cache.
Initializes the cache and adds hooks."
(message "building org-fc cache...")
(org-fc-cache-update)
(org-fc-cache-build)
(add-hook 'org-fc-before-setup-hook #'org-fc-cache-coherence-check)
(setq org-fc-index-function #'org-fc-cache-index)
(message "org-fc cache enabled"))
Expand Down
16 changes: 11 additions & 5 deletions tests/org-fc-indexer-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
(require 'org-fc-test-helper)
(require 'ert)

;; TODO: Ideally we would test indexing multiple files at once but
;; currently there's no way to ignore the order of the results.
(setq
org-fc-test-index-expectations
(let ((algo-sm2 (org-fc-algo-sm2))
(algo-noop (org-fc-algo-noop)))
`((("malformed/no_review_data.org") . ())
(("malformed/no_properties.org") . ())
;; (("malformed/no_properties.org") . ())
(("malformed/normal_swapped_drawers.org") . ())
(("malformed/unclosed_drawer1.org") . ())
(("malformed/unclosed_drawer2.org") . ())
(("escaping/spaces in filename.org")
.
((:cards ((:id "33645f3a-384d-44ed-aed2-a2d56b973800")))))
(("index/uppercase.org" "index/lowercase.org")
(("index/uppercase.org")
.
((:title "File Title Uppercase"
:cards ((:tags ("tag1" "tag2" "fc"))))
(:title "File Title Lowercase"
:cards ((:tags ("tag1" "tag2" "fc"))))))
(("index/lowercase.org")
.
((:title "File Title Lowercase"
:cards ((:tags ("tag3" "tag4" "fc"))))))
(("index/test.org")
.
Expand Down Expand Up @@ -50,8 +54,10 @@
(let* ((files
(mapcar #'org-fc-test-fixture (car expectation)))
(org-fc-directories files)
(org-fc-test-cache org-fc-cache))
(org-fc-test-cache (symbol-value 'org-fc-cache)))
(setq org-fc-cache (make-hash-table :test #'equal))
(org-fc-cache-build)
(org-fc-cache-update)
(org-fc-test-check-structure
(cdr expectation)
(org-fc-cache-index files))
Expand Down

0 comments on commit 00747df

Please sign in to comment.