diff options
| author | Thanos Apollo <public@thanosapollo.org> | 2026-02-23 00:09:55 +0200 |
|---|---|---|
| committer | Thanos Apollo <public@thanosapollo.org> | 2026-02-23 00:48:27 +0200 |
| commit | 2a66b95da7b23cf57a374ad4b2a79a15d2385a0a (patch) | |
| tree | 38e4e2513f8ae478d5e8955e7af093451d29ea4d | |
| parent | e5dcd23a4430b74e6a55663cb57582f62b7faedd (diff) | |
[Refactor] Simplify tags cleanup with a single SQL query.
| -rw-r--r-- | org-gnosis.el | 12 |
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. |
