branch: externals/gnorb
commit 4b19c836c97eb98ba75ab7eb727bb92044572459
Author: Eric Abrahamsen <[email protected]>
Commit: Eric Abrahamsen <[email protected]>
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))))
assoc-msgs)))
+(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
+pruning.
+
+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
key."