Gnus development mailing list
 help / color / mirror / Atom feed
* Don't default to making registry entries for all articles
@ 2020-11-30 20:15 Eric Abrahamsen
  2020-11-30 20:19 ` Eric Abrahamsen
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2020-11-30 20:15 UTC (permalink / raw)
  To: ding; +Cc: Ted Zlatanov

[-- Attachment #1: Type: text/plain, Size: 1307 bytes --]

Hi all,

I've been thinking about how to do this for a while, and think I've got
an okay approach.

The Gnus registry registers everything by default, which slows down
summary buffer creation, and also saving Gnus. The only time you'd
actually want everything registered is if you're splitting using
`gnus-registry-split-fancy-with-parent', which I have to imagine is a
minority of users.

The attached patch lets you change this behavior so the registry only
creates and saves entries that you have made manually, either by setting
a mark on an article, or via some other library.

It does this with a new defcustom, `gnus-registry-register-all-p', which
I'd like to default to nil.

If this is nil, `gnus-registry-register-message-ids' won't do anything.

The patch also adds an optional NO-CREATE argument to
`gnus-registry-get-or-make-entry', to tell it to only get, not make.
Lastly it has `gnus-registry-get-id-key' set that flag to t, so getting
an id key doesn't create a new entry (while setting an id key does).

This last change makes everything else work correctly (spooling and
handling actions) but is also a fairly fundamental change, so I'm hoping
others will look at it closely.

If this is okay, there's also quite a few manual/docs/comments/NEWS
tweaks to make.

Please help test!

Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gnus-registry-no-register.diff --]
[-- Type: text/x-patch, Size: 4970 bytes --]

diff --git a/lisp/gnus/gnus-registry.el b/lisp/gnus/gnus-registry.el
index 65bcd0e8a3..d7f8002745 100644
--- a/lisp/gnus/gnus-registry.el
+++ b/lisp/gnus/gnus-registry.el
@@ -160,6 +160,10 @@ gnus-registry-install
                  (const :tag "Always Install" t)
                  (const :tag "Ask Me" ask)))
 
+(defcustom gnus-registry-register-all-p nil
+  "If non-nil, register all articles in the registry."
+  :type 'boolean)
+
 (defvar gnus-registry-enabled nil)
 
 (defvar gnus-summary-misc-menu) ;; Avoid byte compiler warning.
@@ -478,8 +482,8 @@ gnus-registry-handle-action
   (let ((db gnus-registry-db)
         ;; if the group is ignored, set the destination to nil (same as delete)
         (to (if (gnus-registry-ignore-group-p to) nil to))
-        ;; safe if not found
-        (entry (gnus-registry-get-or-make-entry id))
+        ;; Only retrieve an existing entry, don't create a new one.
+        (entry (gnus-registry-get-or-make-entry id t))
         (subject (gnus-string-remove-all-properties
                   (gnus-registry-simplify-subject subject)))
         (sender (gnus-string-remove-all-properties sender)))
@@ -488,29 +492,30 @@ gnus-registry-handle-action
     ;; several times but it's better to bunch the transactions
     ;; together
 
-    (registry-delete db (list id) nil)
-    (when from
-      (setq entry (cons (delete from (assoc 'group entry))
-                        (assq-delete-all 'group entry))))
-    ;; Only keep the entry if the message is going to a new group, or
-    ;; it's still in some previous group.
-    (when (or to (alist-get 'group entry))
-      (dolist (kv `((group ,to)
-                    (sender ,sender)
-                    (recipient ,@recipients)
-                    (subject ,subject)))
-	(when (cadr kv)
-          (let ((new (or (assq (car kv) entry)
-			 (list (car kv)))))
-            (dolist (toadd (cdr kv))
-              (unless (member toadd new)
-		(setq new (append new (list toadd)))))
-            (setq entry (cons new
-                              (assq-delete-all (car kv) entry))))))
-      (gnus-message 10 "Gnus registry: new entry for %s is %S"
-                    id
-                    entry)
-      (gnus-registry-insert db id entry))))
+    (when entry
+      (registry-delete db (list id) nil)
+      (when from
+	(setq entry (cons (delete from (assoc 'group entry))
+                          (assq-delete-all 'group entry))))
+      ;; Only keep the entry if the message is going to a new group, or
+      ;; it's still in some previous group.
+      (when (or to (alist-get 'group entry))
+	(dolist (kv `((group ,to)
+                      (sender ,sender)
+                      (recipient ,@recipients)
+                      (subject ,subject)))
+	  (when (cadr kv)
+            (let ((new (or (assq (car kv) entry)
+			   (list (car kv)))))
+              (dolist (toadd (cdr kv))
+		(unless (member toadd new)
+		  (setq new (append new (list toadd)))))
+              (setq entry (cons new
+				(assq-delete-all (car kv) entry))))))
+	(gnus-message 10 "Gnus registry: new entry for %s is %S"
+                      id
+                      entry)
+	(gnus-registry-insert db id entry)))))
 
 ;; Function for nn{mail|imap}-split-fancy: look up all references in
 ;; the cache and if a match is found, return that group.
@@ -846,7 +851,8 @@ gnus-registry-find-keywords
 
 (defun gnus-registry-register-message-ids ()
   "Register the Message-ID of every article in the group."
-  (unless (gnus-parameter-registry-ignore gnus-newsgroup-name)
+  (unless (or (gnus-parameter-registry-ignore gnus-newsgroup-name)
+	      (null gnus-registry-register-all-p))
     (dolist (article gnus-newsgroup-articles)
       (let* ((id (gnus-registry-fetch-message-id-fast article))
              (groups (gnus-registry-get-id-key id 'group)))
@@ -1082,12 +1088,15 @@ gnus-registry-group-count
   "Get the number of groups of a message, based on the message ID."
   (length (gnus-registry-get-id-key id 'group)))
 
-(defun gnus-registry-get-or-make-entry (id)
+(defun gnus-registry-get-or-make-entry (id &optional no-create)
+  "Return registry entry for ID.
+If entry is not found, create a new one, unless NO-create is
+non-nil."
   (let* ((db gnus-registry-db)
          ;; safe if not found
          (entries (registry-lookup db (list id))))
 
-    (when (null entries)
+    (unless (or entries no-create)
       (gnus-registry-insert db id (list (list 'creation-time (current-time))
                                         '(group) '(sender) '(subject)))
       (setq entries (registry-lookup db (list id))))
@@ -1098,7 +1107,7 @@ gnus-registry-delete-entries
   (registry-delete gnus-registry-db idlist nil))
 
 (defun gnus-registry-get-id-key (id key)
-  (cdr-safe (assq key (gnus-registry-get-or-make-entry id))))
+  (cdr-safe (assq key (gnus-registry-get-or-make-entry id t))))
 
 (defun gnus-registry-set-id-key (id key vals)
   (let* ((db gnus-registry-db)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Don't default to making registry entries for all articles
  2020-11-30 20:15 Don't default to making registry entries for all articles Eric Abrahamsen
@ 2020-11-30 20:19 ` Eric Abrahamsen
  2020-12-12 17:06   ` Eric Abrahamsen
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2020-11-30 20:19 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Hi all,
>
> I've been thinking about how to do this for a while, and think I've got
> an okay approach.
>
> The Gnus registry registers everything by default, which slows down
> summary buffer creation, and also saving Gnus. The only time you'd
> actually want everything registered is if you're splitting using
> `gnus-registry-split-fancy-with-parent', which I have to imagine is a
> minority of users.
>
> The attached patch lets you change this behavior so the registry only
> creates and saves entries that you have made manually, either by setting
> a mark on an article, or via some other library.
>
> It does this with a new defcustom, `gnus-registry-register-all-p', which
> I'd like to default to nil.
>
> If this is nil, `gnus-registry-register-message-ids' won't do anything.
>
> The patch also adds an optional NO-CREATE argument to
> `gnus-registry-get-or-make-entry', to tell it to only get, not make.
> Lastly it has `gnus-registry-get-id-key' set that flag to t, so getting
> an id key doesn't create a new entry (while setting an id key does).

I suppose a slightly less intrusive approach would be to have
`gnus-registry-get-id-key' also check the value of
`gnus-registry-register-all-p', and pass the NO-CREATE flag accordingly.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Don't default to making registry entries for all articles
  2020-11-30 20:19 ` Eric Abrahamsen
@ 2020-12-12 17:06   ` Eric Abrahamsen
  2020-12-13  3:54     ` 황병희
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2020-12-12 17:06 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Hi all,
>>
>> I've been thinking about how to do this for a while, and think I've got
>> an okay approach.
>>
>> The Gnus registry registers everything by default, which slows down
>> summary buffer creation, and also saving Gnus. The only time you'd
>> actually want everything registered is if you're splitting using
>> `gnus-registry-split-fancy-with-parent', which I have to imagine is a
>> minority of users.
>>
>> The attached patch lets you change this behavior so the registry only
>> creates and saves entries that you have made manually, either by setting
>> a mark on an article, or via some other library.
>>
>> It does this with a new defcustom, `gnus-registry-register-all-p', which
>> I'd like to default to nil.
>>
>> If this is nil, `gnus-registry-register-message-ids' won't do anything.
>>
>> The patch also adds an optional NO-CREATE argument to
>> `gnus-registry-get-or-make-entry', to tell it to only get, not make.
>> Lastly it has `gnus-registry-get-id-key' set that flag to t, so getting
>> an id key doesn't create a new entry (while setting an id key does).
>
> I suppose a slightly less intrusive approach would be to have
> `gnus-registry-get-id-key' also check the value of
> `gnus-registry-register-all-p', and pass the NO-CREATE flag accordingly.

Okay, this has now gone in. The option is called
`gnus-registry-register-all', and defaults to t to preserve behavior, so
you'll have to set that explicitly if you don't want to save everything.

Eric



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Don't default to making registry entries for all articles
  2020-12-12 17:06   ` Eric Abrahamsen
@ 2020-12-13  3:54     ` 황병희
  0 siblings, 0 replies; 4+ messages in thread
From: 황병희 @ 2020-12-13  3:54 UTC (permalink / raw)
  To: The Gnus

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>
>>> Hi all,
>>>
>>> I've been thinking about how to do this for a while, and think I've got
>>> an okay approach.
>>>
>>> The Gnus registry registers everything by default, which slows down
>>> summary buffer creation, and also saving Gnus. The only time you'd
>>> actually want everything registered is if you're splitting using
>>> `gnus-registry-split-fancy-with-parent', which I have to imagine is a
>>> minority of users.
>>>
>>> The attached patch lets you change this behavior so the registry only
>>> creates and saves entries that you have made manually, either by setting
>>> a mark on an article, or via some other library.
>>>
>>> It does this with a new defcustom, `gnus-registry-register-all-p', which
>>> I'd like to default to nil.
>>>
>>> If this is nil, `gnus-registry-register-message-ids' won't do anything.
>>>
>>> The patch also adds an optional NO-CREATE argument to
>>> `gnus-registry-get-or-make-entry', to tell it to only get, not make.
>>> Lastly it has `gnus-registry-get-id-key' set that flag to t, so getting
>>> an id key doesn't create a new entry (while setting an id key does).
>>
>> I suppose a slightly less intrusive approach would be to have
>> `gnus-registry-get-id-key' also check the value of
>> `gnus-registry-register-all-p', and pass the NO-CREATE flag accordingly.
>
> Okay, this has now gone in. The option is called
> `gnus-registry-register-all', and defaults to t to preserve behavior, so
> you'll have to set that explicitly if you don't want to save everything.
>

Hellow Eric! Everytime, thanks for your efforts! After upgrading my
Ubuntu, i will try to your concern with Gnus.

Sincerely, Gnus fan Byung-Hee

-- 
^고맙습니다 _布德天下_ 감사합니다_^))//


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-13  3:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 20:15 Don't default to making registry entries for all articles Eric Abrahamsen
2020-11-30 20:19 ` Eric Abrahamsen
2020-12-12 17:06   ` Eric Abrahamsen
2020-12-13  3:54     ` 황병희

Gnus development mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/ding

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 ding ding/ http://inbox.vuxu.org/ding \
		ding@inbox.vuxu.org
	public-inbox-index ding

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.emacs.gnus.general


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git