[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/gnorb 4b19c83 288/449: New function for pruning dead as

From: Stefan Monnier
Subject: [elpa] externals/gnorb 4b19c83 288/449: New function for pruning dead associations
Date: Fri, 27 Nov 2020 23:15:57 -0500 (EST)

branch: externals/gnorb
commit 4b19c836c97eb98ba75ab7eb727bb92044572459
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    New function for pruning dead associations
    * gnorb-registry.el (gnorb-flush-dead-associations): New function.
      Removes gnorb-id values from registry entries when those values no
      longer point at existing Org headings.
    Useful for when the registry is full of entries with the gnorb-id key
    set, and pruning can't remove them.
 gnorb-registry.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/gnorb-registry.el b/gnorb-registry.el
index bd2e07a..9ff4ab3 100644
--- a/gnorb-registry.el
+++ b/gnorb-registry.el
@@ -163,6 +163,37 @@ after an Org heading is deleted, for instance."
          msg-id 'gnorb-ids (remove org-id org-ids))))
+(defun gnorb-flush-dead-associations (&optional clean-archived)
+  "Clean the registry of associations with nonexistent headings.
+Gnus will not prune registry entries that appear to be associated
+with an Org heading.  If your registry is limited to a very small
+size, you may end up with a full registry.  Use this function to
+remove dead associations, and free up more entries for possible
+By default, associations are considered \"live\" if the Org
+heading exists in an Org file or in an Org archive file.  When
+optional CLEAN_ARCHIVED is non-nil, delete associations from
+archived headings as well."
+  (interactive "P")
+  (let ((gnorb-id-tracker
+        (registry-lookup-secondary gnus-registry-db 'gnorb-ids))
+       (deleted-count 0))
+    (require 'org-id)
+    (maphash
+     (lambda (k _)
+       (let ((file (org-id-find-id-file k)))
+        (unless
+            (and file
+                 (and clean-archived
+                      (string-match-p "org_archive$" file)))
+          (gnorb-delete-all-associations k)
+          (incf deleted-count))))
+     gnorb-id-tracker)
+    (message "Disassociated %d nonexistent Org headings"
+            deleted-count)))
 (defun gnorb-registry-org-id-search (id)
   "Find all messages that have the org ID in their 'gnorb-ids

reply via email to

[Prev in Thread] Current Thread [Next in Thread]