summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <public@thanosapollo.org>2026-02-23 00:09:55 +0200
committerThanos Apollo <public@thanosapollo.org>2026-02-23 00:48:27 +0200
commit2a66b95da7b23cf57a374ad4b2a79a15d2385a0a (patch)
tree38e4e2513f8ae478d5e8955e7af093451d29ea4d
parente5dcd23a4430b74e6a55663cb57582f62b7faedd (diff)
[Refactor] Simplify tags cleanup with a single SQL query.
-rw-r--r--org-gnosis.el12
1 files 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.