From 0a7d365e226b59674a97baddb8b3419762a00b6e Mon Sep 17 00:00:00 2001 From: Bill Burdick Date: Fri, 30 Apr 2021 00:51:29 -0400 Subject: [PATCH] speed up org-roam-db-sync by wrapping db activity in a transaction (#1495) In my case of testing with 8253 zettels (available on request if anyone wants to test with them), this improves cleanup speed by 6x and update speed by 2x. Improvements will be smaller for smaller batches as this really just removes the transaction overhead. --- org-roam-db.el | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/org-roam-db.el b/org-roam-db.el index f9e3b30..99f99a9 100644 --- a/org-roam-db.el +++ b/org-roam-db.el @@ -435,18 +435,19 @@ If FORCE, force a rebuild of the cache from scratch." contents-hash) (push file modified-files))) (remhash file current-files)) - (if (fboundp 'dolist-with-progress-reporter) - (dolist-with-progress-reporter (file (hash-table-keys current-files)) - "Clearing removed files..." - (org-roam-db-clear-file file)) - (dolist (file (hash-table-keys current-files)) - (org-roam-db-clear-file file))) - (if (fboundp 'dolist-with-progress-reporter) - (dolist-with-progress-reporter (file modified-files) - "Processing modified files..." - (org-roam-db-update-file file)) - (dolist (file modified-files) - (org-roam-db-update-file file))))) + (emacsql-with-transaction (org-roam-db) + (if (fboundp 'dolist-with-progress-reporter) + (dolist-with-progress-reporter (file (hash-table-keys current-files)) + "Clearing removed files..." + (org-roam-db-clear-file file)) + (dolist (file (hash-table-keys current-files)) + (org-roam-db-clear-file file))) + (if (fboundp 'dolist-with-progress-reporter) + (dolist-with-progress-reporter (file modified-files) + "Processing modified files..." + (org-roam-db-update-file file)) + (dolist (file modified-files) + (org-roam-db-update-file file)))))) (defun org-roam-db-update-file (&optional file-path) "Update Org-roam cache for FILE-PATH.