stardiviner <[email protected]> writes:

> I'm using the package "org-roam" https://github.com/org-roam/org-roam.
>
> But when I have lot of Org files under `org-directory' & `org-roam-directory'.
> Then org-roam update ID locations with command 
> `org-roam-update-org-id-locations',
> and `org-roam-db-sync` will suspend and spend a long time for Emacs.
>
> So I think update ID locations on every `after-save-hook` everytime file
> updated for new :ID: locations using an "incremental way". This can
> avoid run `org-id-update-id-locations' globally scan lots of files
> repeatedly.

> Bellowing is my prototype code (not a patch) for my propose for your 
> reference.

I agree that granular per-file caching makes more sense.
I implemented a simple checksum approach for all possible files
together. Doing the same for each file individually will be better.

> #+begin_src emacs-lisp
> ;; TEMP: extract core logic from `org-id-update-id-locations'
> (defun org-id-update-id-locations-for-file (&optional file silent)
>     "Scan relevant file for IDs.
> Store the relation between file and corresponding IDs.
> If SILENT is non-nil, messages are suppressed."
>     (interactive nil org-mode)
>     (let* ((file (or file (buffer-file-name)))
>            (id-regexp (rx (seq bol (0+ (any "\t ")) ":ID:" (1+ " ") (not (any 
> " ")))))
>            (checksum (when (file-exists-p file)
>                        (list file (file-attribute-modification-time 
> (file-attributes file)))))
>            (id-locations nil))
>       (unless (equal checksum org-id--locations-checksum) ; Files have 
> changed since the last update.
> ...
>         (setq org-id--locations-checksum checksum)

This will only remember the latest processed file and will still re-scan
everything if we process another file. We should instead make
org-id--locations-checksum a hash table with keys being files and values
being their checksums. Then, check and update the values individually
for each file.

> Hope maintainer @Carsten Dominik (who is author of org-id.el) or Ihor can 
> complete the patch.
> Because I can't totally figure out the logic, and pass the testing, etc.

Carsten is no longer a maintainer of org-id. He retired from being the
maintainer long time ago :)

As for completing the patch, FYI, improving performance of org-id has
been on my list for a long time. However, I have to prioritize, and that
item is nowhere near the top of my list. I will certainly help you
finish the patch if you are up to doing it, but the chance that I will
do the patch myself is rather low.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to