From 2a66b95da7b23cf57a374ad4b2a79a15d2385a0a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Mon, 23 Feb 2026 00:09:55 +0200 Subject: [Refactor] Simplify tags cleanup with a single SQL query. --- org-gnosis.el | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/org-gnosis.el b/org-gnosis.el index 3a9a39b..f86f5f5 100644 --- a/org-gnosis.el +++ b/org-gnosis.el @@ -422,14 +422,10 @@ If JOURNAL is non-nil, update file as a journal entry." (org-gnosis--delete 'nodes `(= id ,node))))))) (defun org-gnosis-tags--cleanup-orphaned () - "Remove orphaned tags that have no associated nodes. -Efficient: only checks tags not in node-tag table." - (let* ((all-tags (org-gnosis-select 'tag 'tags nil t)) - (used-tags (org-gnosis-select 'tag 'node-tag nil t)) - (orphaned (cl-set-difference all-tags used-tags :test #'equal))) - (when orphaned - (dolist (tag orphaned) - (emacsql (org-gnosis-db-get) [:delete :from tags :where (= tag $s1)] tag))))) + "Remove orphaned tags that have no associated nodes." + (emacsql (org-gnosis-db-get) + [:delete :from tags + :where (not-in tag [:select :distinct tag :from node-tag])])) (defun org-gnosis-update-file (&optional file) "Update contents of FILE in database. -- cgit v1.0