From 1922ebcd047c4ea6ebdf8db1ee9bbabdaf54e687 Mon Sep 17 00:00:00 2001 From: Gustav Wikström Date: Mon, 22 Feb 2021 23:03:34 +0100 Subject: Speedup crawler by ... making it not crawl! --- nroam.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/nroam.el b/nroam.el index bbadffb..74fcbbb 100644 --- a/nroam.el +++ b/nroam.el @@ -44,6 +44,7 @@ (defvar-local nroam-start-marker nil) (defvar-local nroam-end-marker nil) +(defvar nroam-work-buffer " nroam-work") (defmacro with-nroam-markers (&rest body) "Evaluate BODY. Make the region inserted by BODY read-only, and marked with @@ -68,6 +69,7 @@ Make the region inserted by BODY read-only, and marked with :keymap nroam-mode-map (if nroam-mode (progn + (nroam--init-work-buffer) (add-hook 'before-save-hook #'nroam--prune-backlinks nil t) (add-hook 'after-save-hook #'nroam--update-backlinks-maybe nil t) (nroam-update-backlinks)) @@ -75,6 +77,12 @@ Make the region inserted by BODY read-only, and marked with (remove-hook 'after-save-hook #'nroam--update-backlinks-maybe t) (nroam--prune-backlinks))) +(defun nroam--init-work-buffer () + (get-buffer-create nroam-work-buffer t) + (with-current-buffer nroam-work-buffer + (delay-mode-hooks + (org-mode)))) + (defun nroam-ctrl-c-ctrl-c () "Update the backlinks for the current buffer, or fallback to `org-ctrl-c-ctrl-c'." (interactive) @@ -198,14 +206,14 @@ Make the region inserted by BODY read-only, and marked with (defun nroam--crawl-source (file point) "Return the source element in FILE at POINT." - (with-current-buffer (find-file-noselect file) - (save-excursion - (goto-char point) - (let ((elt (org-element-at-point))) - (let ((begin (org-element-property :begin elt)) - (end (org-element-property :end elt)) - (type (org-element-type elt))) - `(,type . ,(buffer-substring begin end))))))) + (with-current-buffer nroam-work-buffer + (insert-file-contents file nil nil nil 'replace) + (goto-char point) + (let ((elt (org-element-at-point))) + (let ((begin (org-element-property :begin elt)) + (end (org-element-property :end elt)) + (type (org-element-type elt))) + `(,type . ,(buffer-substring begin end)))))) (defun nroam--fix-links (content origin) "Correct all relative links in CONTENT from ORIGIN. -- cgit v1.3-2-g0d8e From 4a9159db02829b51e9a7e21bc0f85f734c8e1b64 Mon Sep 17 00:00:00 2001 From: Gustav Wikström Date: Mon, 22 Feb 2021 23:29:17 +0100 Subject: Readme.org: Performance part not needed due to crawler changes Crawler doesn't crawl any longer and has no performance issues any longer, no matter how big the Org roam library. --- readme.org | 5 ----- 1 file changed, 5 deletions(-) diff --git a/readme.org b/readme.org index ced0d91..d16507d 100644 --- a/readme.org +++ b/readme.org @@ -26,8 +26,3 @@ It can also be manually updated by typing =C-c C-c= anywhere in the linked refer * Warning This package is in its infancy. Be careful when using it as it modifies your =org-mode= buffers—it should not modify your files though. Backup your data often. - -* Performance - -At the moment no caching is done when crawling source files for backlinks so there could be performance issues with very large number of org files as a lot of buffers could have to be open to crawl backlink content. - -- cgit v1.3-2-g0d8e From 3a0d7a3696f3bebc4fe117e18d94068443aaca83 Mon Sep 17 00:00:00 2001 From: Gustav Wikström Date: Tue, 23 Feb 2021 14:37:45 +0100 Subject: Add docstring and empty line * nroam.el (nroam--init-work-buffer): Add docstring. --- nroam.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nroam.el b/nroam.el index 74fcbbb..5120905 100644 --- a/nroam.el +++ b/nroam.el @@ -45,6 +45,7 @@ (defvar-local nroam-end-marker nil) (defvar nroam-work-buffer " nroam-work") + (defmacro with-nroam-markers (&rest body) "Evaluate BODY. Make the region inserted by BODY read-only, and marked with @@ -78,6 +79,7 @@ Make the region inserted by BODY read-only, and marked with (nroam--prune-backlinks))) (defun nroam--init-work-buffer () + "Initiate nroam hidden buffer." (get-buffer-create nroam-work-buffer t) (with-current-buffer nroam-work-buffer (delay-mode-hooks -- cgit v1.3-2-g0d8e