emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/gnorb 3f9c534 312/449: Report Gnorb email tracking usag


From: Stefan Monnier
Subject: [elpa] externals/gnorb 3f9c534 312/449: Report Gnorb email tracking usage
Date: Fri, 27 Nov 2020 23:16:02 -0500 (EST)

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

    Report Gnorb email tracking usage
    
    * gnorb-registry.el (gnorb-report-tracking-usage,
      gnorb-refresh-usage-status): New functions for popping up a
      window in special mode, displaying Gnorb usage of the registry.
      Additional keybindings for `gnorb-flush-dead-associations'.
      (gnorb-flush-dead-associations): Fix incorrect logic for handling
      "clean-archived" parameter.
      (gnorb-delete-all-associations): Remove id from registry tracker after
      deleting assocations.
    
    * gnorb.org: Document
    * gnorb.texi
    * gnorb.info
---
 gnorb-registry.el | 67 ++++++++++++++++++++++++++++++++++++++++++++++------
 gnorb.info        | 70 +++++++++++++++++++++++++++++++++----------------------
 gnorb.org         |  5 ++++
 gnorb.texi        | 10 ++++++++
 4 files changed, 117 insertions(+), 35 deletions(-)

diff --git a/gnorb-registry.el b/gnorb-registry.el
index d4af885..71e86cf 100644
--- a/gnorb-registry.el
+++ b/gnorb-registry.el
@@ -150,14 +150,17 @@ the MSG-ID."
 
 The heading is identified by ORG-ID. This is suitable for use
 after an Org heading is deleted, for instance."
-  (let ((assoc-msgs (gnorb-registry-org-id-search org-id)))
+  (let ((assoc-msgs (gnorb-registry-org-id-search org-id))
+       (gnorb-id-tracker
+        (registry-lookup-secondary gnus-registry-db 'gnorb-ids)))
     (mapcar
      (lambda (msg-id)
        (let ((org-ids
              (gnus-registry-get-id-key msg-id 'gnorb-ids)))
         (gnus-registry-set-id-key
          msg-id 'gnorb-ids (remove org-id org-ids))))
-     assoc-msgs)))
+     assoc-msgs)
+    (remhash org-id gnorb-id-tracker)))
 
 (defun gnorb-flush-dead-associations (&optional clean-archived)
   "Clean the registry of associations with nonexistent headings.
@@ -180,14 +183,13 @@ archived headings as well."
     (maphash
      (lambda (k _)
        (let ((file (org-id-find-id-file k)))
-        (unless
-            (and file
-                 (and clean-archived
-                      (string-match-p "org_archive$" file)))
+        (when (or (not 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"
+    (message "Deleted %d invalid associations"
             deleted-count)))
 
 (defun gnorb-registry-org-id-search (id)
@@ -199,6 +201,57 @@ key."
   "Return all message-ids that have non-empty 'gnorb-ids keys."
   (registry-search gnus-registry-db :regex `((gnorb-ids ".+"))))
 
+(defun gnorb-registry-tracked-headings ()
+  "Return all Org heading ids that are associated with messages."
+  (hash-table-keys
+   (registry-lookup-secondary gnus-registry-db 'gnorb-ids)))
+
+(defun gnorb-report-tracking-usage ()
+  "Pop up a temporary window reporting on Gnorb usage of the Gnus
+registry to track message/heading associations.  Reports the
+number of tracked messages, the number of tracked headings, and how much of 
the registry is occupied."
+  (interactive)
+  (progn
+    (pop-to-buffer
+     (get-buffer-create "*Gnorb Usage*")
+     '(nil . ((window-height . 10))))
+    (gnorb-refresh-usage-status)
+    (special-mode)
+    (setq revert-buffer-function #'gnorb-refresh-usage-status)
+    (local-set-key (kbd "d") (lambda ()
+                              (interactive)
+                              (progn
+                                (gnorb-flush-dead-associations)
+                                (gnorb-refresh-usage-status))))
+    (local-set-key (kbd "D") (lambda ()
+                              (interactive)
+                              (progn
+                                (gnorb-flush-dead-associations t)
+                                (gnorb-refresh-usage-status))))))
+
+(defun gnorb-refresh-usage-status (&optional ignore-auto noconfirm)
+  "Clear and re-format the *Gnorb Usage* buffer."
+  (let ((messages (length (gnorb-registry-tracked-messages)))
+       (headings (length (gnorb-registry-tracked-headings)))
+       (reg-size (registry-size gnus-registry-db))
+       (reg-max-size (oref gnus-registry-db max-size)))
+    (with-current-buffer "*Gnorb Usage*"
+      (let ((inhibit-read-only t))
+       (erase-buffer)
+       (insert
+       (format
+        "Tracking %d Gnus messages associated with %d Org headings."
+        messages headings))
+       (insert "\n\n")
+       (insert
+       (format
+        "Occupying %.2f%% (%d/%d) of the registry (max %d)."
+        (* 100 (/ (float messages) reg-size))
+        messages reg-size reg-max-size))
+       (insert "\n\n")
+       (insert "Press 'd' to delete associations for non-existent Org 
headings.\n")
+       (insert "Press 'D' to delete associations for both non-existent and 
archived Org headings.")))))
+
 (defun gnorb-registry-transition-from-props (arg)
   "Helper function for transitioning the old tracking system to the new.
 
diff --git a/gnorb.info b/gnorb.info
index 4cd23ef..0a9da39 100644
--- a/gnorb.info
+++ b/gnorb.info
@@ -35,6 +35,7 @@ Email Tracking
 * Viewing Tracked Messages in *Summary* Buffers::
 * Hinting in Gnus::
 * Message Attachments::
+* Registry Usage::
 * Likely Workflow::
 
 Misc BBDB
@@ -155,6 +156,7 @@ agenda rather than in Gnus.
 * Viewing Tracked Messages in *Summary* Buffers::
 * Hinting in Gnus::
 * Message Attachments::
+* Registry Usage::
 * Likely Workflow::
 
 
@@ -295,7 +297,7 @@ is “g” (meaning it is used as “%ug” in the format line), 
and the mark is
 “¡”.
 
 
-File: gnorb.info,  Node: Message Attachments,  Next: Likely Workflow,  Prev: 
Hinting in Gnus,  Up: Email Tracking
+File: gnorb.info,  Node: Message Attachments,  Next: Registry Usage,  Prev: 
Hinting in Gnus,  Up: Email Tracking
 
 4.5 Message Attachments
 =======================
@@ -322,9 +324,20 @@ attach the files in the heading’s org-attach directory to 
the outgoing
 message.
 
 
-File: gnorb.info,  Node: Likely Workflow,  Prev: Message Attachments,  Up: 
Email Tracking
+File: gnorb.info,  Node: Registry Usage,  Next: Likely Workflow,  Prev: 
Message Attachments,  Up: Email Tracking
 
-4.6 Likely Workflow
+4.6 Registry Usage
+==================
+
+You can see how many associations you’ve got stored in the registry by
+calling ‘gnorb-report-tracking-usage’.  This will pop up a buffer
+showing how the number of associations, and offering keybindings for
+‘gnorb-flush-dead-associations’, to help Gnorb clean up after itself.
+
+
+File: gnorb.info,  Node: Likely Workflow,  Prev: Registry Usage,  Up: Email 
Tracking
+
+4.7 Likely Workflow
 ===================
 
 You receive an email from Jimmy, who wants to rent a room in your house.
@@ -706,31 +719,32 @@ File: gnorb.info,  Node: Suggested Keybindings,  Prev: 
Misc Gnus,  Up: Top
 
 Tag Table:
 Node: Top194
-Node: Introduction1009
-Node: Installation2118
-Node: Setup2532
-Node: Email Tracking3899
-Node: Email-Related Commands5430
-Node: Trigger Actions8801
-Node: Viewing Tracked Messages in *Summary* Buffers9650
-Node: Hinting in Gnus11146
-Node: Message Attachments12154
-Node: Likely Workflow13336
-Node: Restoring Window Layout16141
-Node: Recent Mails From BBDB Contacts16505
-Node: BBDB posting styles17501
-Node: BBDB Org tagging18417
-Node: Misc BBDB19163
-Node: Searching for messages from BBDB contacts19376
-Node: Citing BBDB contacts19822
-Node: User Options20143
-Node: Misc Org21682
-Node: Inserting BBDB links21857
-Node: User Optionsx22112
-Node: Misc Gnus24849
-Node: Viewing Org headlines relevant to a message25062
-Node: User Optionsxx25377
-Node: Suggested Keybindings28141
+Node: Introduction1028
+Node: Installation2137
+Node: Setup2551
+Node: Email Tracking3918
+Node: Email-Related Commands5468
+Node: Trigger Actions8839
+Node: Viewing Tracked Messages in *Summary* Buffers9688
+Node: Hinting in Gnus11184
+Node: Message Attachments12192
+Node: Registry Usage13373
+Node: Likely Workflow13815
+Node: Restoring Window Layout16615
+Node: Recent Mails From BBDB Contacts16979
+Node: BBDB posting styles17975
+Node: BBDB Org tagging18891
+Node: Misc BBDB19637
+Node: Searching for messages from BBDB contacts19850
+Node: Citing BBDB contacts20296
+Node: User Options20617
+Node: Misc Org22156
+Node: Inserting BBDB links22331
+Node: User Optionsx22586
+Node: Misc Gnus25323
+Node: Viewing Org headlines relevant to a message25536
+Node: User Optionsxx25851
+Node: Suggested Keybindings28615
 
 End Tag Table
 
diff --git a/gnorb.org b/gnorb.org
index 380f657..c39d61f 100644
--- a/gnorb.org
+++ b/gnorb.org
@@ -219,6 +219,11 @@ The same process works in reverse: when you send a message 
from an Org
 heading using `gnorb-org-handle-mail', Gnorb will ask if you want to
 attach the files in the heading's org-attach directory to the outgoing
 message.
+** Registry Usage
+You can see how many associations you've got stored in the registry by
+calling `gnorb-report-tracking-usage'. This will pop up a buffer
+showing how the number of associations, and offering keybindings for
+`gnorb-flush-dead-associations', to help Gnorb clean up after itself.
 ** Likely Workflow
 You receive an email from Jimmy, who wants to rent a room in your
 house. "I'll respond to this later," you think.
diff --git a/gnorb.texi b/gnorb.texi
index 1cd0ce5..ad4a876 100644
--- a/gnorb.texi
+++ b/gnorb.texi
@@ -47,6 +47,7 @@ Email Tracking
 * Viewing Tracked Messages in *Summary* Buffers::
 * Hinting in Gnus::
 * Message Attachments::
+* Registry Usage::
 * Likely Workflow::
 
 Misc BBDB
@@ -162,6 +163,7 @@ agenda rather than in Gnus.
 * Viewing Tracked Messages in *Summary* Buffers::
 * Hinting in Gnus::
 * Message Attachments::
+* Registry Usage::
 * Likely Workflow::
 @end menu
 
@@ -324,6 +326,14 @@ heading using `gnorb-org-handle-mail', Gnorb will ask if 
you want to
 attach the files in the heading's org-attach directory to the outgoing
 message.
 
+@node Registry Usage
+@section Registry Usage
+
+You can see how many associations you've got stored in the registry by
+calling `gnorb-report-tracking-usage'. This will pop up a buffer
+showing how the number of associations, and offering keybindings for
+`gnorb-flush-dead-associations', to help Gnorb clean up after itself.
+
 @node Likely Workflow
 @section Likely Workflow
 



reply via email to

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