Speed up indexing / filtering of cards by caching the card index, updating entries when files change.
After initializing the cache, indexing operations are nearly 100x faster in my benchmarks.
I've pushed a prototype of a caching indexer, it can enabled / disabled with
org-fc-cache-mode
.Assuming only a small subset of files managed by org-fc changes during each review, it's much faster than indexing all files all the time.
The code is untested but the dashboard and reviewing cards work (and are noticably faster).
In case this cache becomes incoherent due to some bug in the code, numbers shown in the dashboard will be inaccurate. The worst thing that can happen when the cache is incoherent is that cards are scheduled for review before they are due. To prevent that, before each review the data of the current card is compared to the cached data and if they differ, an error is raised.
In that case, you can disable the cache with
org-fc-cache-mode
and continue using org-fc as usual, without any risk of "damaging" the review/spacing data.
I've been using the cache mode without problems for the last few days. File titles were missing during the review but that has been fixed with the last commit.
I have started using the cache mode and began getting the error
org-fc-review-next-card: Symbol’s value as variable is void: cur
.I think it is because the macro
org-fc-review-with-current-item
expects the current card to be setup/session to be setup in order to read from the org-fc--session variable. However, the functionorg-fc-cache-coherence-check
is added to theorg-fc-before-setup-hook
upon activation oforg-fc-cache-mode
.Would there be any significant affect if that is changed to
org-fc-after-setup-hook
?(defun org-fc-cache-coherence-check () "Check if the entry at point is coherent with its cache representation. This is especially relevant w.r.t a card's due date / suspension state before review." (org-fc-review-with-current-item cur (if (org-fc-suspended-entry-p) (error "Trying to review a suspended card")) (let* ((position (plist-get cur :position)) (review-data (org-fc-get-review-data)) (row (assoc position review-data #'string=)) (due (parse-iso8601-time-string (nth 4 row)))) (unless (time-less-p due (current-time)) (error "Trying to review a non-due card")))))
The
before-setup-hook
runs after a new card is set and before it is set up using the setup function of the card type, so I don't think the session not being defined is the core problem here.However, I had placed the
(require 'org-fc-cache)
at a point where thereview-with-current-item
macro is not yet defined, loading the cache code it would be considered as a function with an undefined argumentcur
which might explain your error.Another problem I found is that reviewing single buffers outside of the
org-fc-directories
doesn't work when cache-mode is active. (not fixed yet)Did you notice any speedup with your setup when using the cache mode?
The coherence check is a bit of a hack to make sure using the cache doesn't do any damage, I think it could just be moved into the
with-current-item
macro once we know the cache works as expected (and ideally have some tests for it).
Even when requiring the cache code later, I ran into the same error trying to use cache-mode on a fresh emacs instance. I'm not sure why this is happening, adding an
autoload
seems to have fixed it.