From 661e388bba2b71b2d8b3db287b7f77e400b452f6 Mon Sep 17 00:00:00 2001 From: Ahmed Shariff Date: Fri, 29 Nov 2024 18:56:51 -0800 Subject: [PATCH] Invalidate cache based on db mtime --- org-roam-ql.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/org-roam-ql.el b/org-roam-ql.el index c182d4b..424fbf1 100644 --- a/org-roam-ql.el +++ b/org-roam-ql.el @@ -50,6 +50,7 @@ (defvar org-roam-ql--sort-functions (make-hash-table :test 'equal) "Holds the function to sort nodes.") (defvar org-roam-ql--saved-queries (make-hash-table :test 'equal) "Holds the saved queries.") (defvar org-roam-ql--cache (make-hash-table)) +(defvar org-roam-ql--db-mtime nil) (defvar org-roam-ql--search-query-history '() "History of queries with `org-roam-ql-search'.") (defvar-local org-roam-ql-buffer-title nil "The current title of the buffer.") (defvar-local org-roam-ql-buffer-query nil "The current query of the buffer.") @@ -166,6 +167,13 @@ See `org-roam-ql-nodes' for information on SOURCE-OR-QUERY. Not caching or invalidating in the top level function as the database/buffers can change. Currently this is only used by the internal functions" + (let ((db-mtime (time-convert + (file-attribute-modification-time + (file-attributes (file-truename org-roam-db-location))) + 'integer))) + (unless (equal db-mtime org-roam-ql--db-mtime) + (org-roam-ql-clear-cache) + (setq org-roam-ql--db-mtime db-mtime))) (let ((cached-value (gethash source-or-query org-roam-ql--cache))) (if cached-value cached-value