From 935129c3eb9366507537d51f14332d7ce148befb Mon Sep 17 00:00:00 2001 From: Teodor Zlatanov Date: Tue, 6 Jan 2004 22:46:32 +0000 Subject: [PATCH] (spam-cache-lookups, spam-caches, spam-clear-cache): first attempt at some caching support (done for BBDB only now) (spam-find-spam): set spam-cache-lookups if there are more than 2 addresses to be checked (spam-clear-cache-BBDB): new function, to be invoked by bbdb-change-hook, and triggering spam-clear-cache of 'spam-use-BBDB (spam-check-BBDB): check and use the caches, if spam-cache-lookups is on remove superfluous (provide) --- lisp/ChangeLog | 12 +++++++++++ lisp/spam.el | 55 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e04debf69..c0b6844dc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2004-01-06 Teodor Zlatanov + + * spam.el (spam-cache-lookups, spam-caches, spam-clear-cache): + first attempt at some caching support (done for BBDB only now) + (spam-find-spam): set spam-cache-lookups if there are more than 2 + addresses to be checked + (spam-clear-cache-BBDB): new function, to be invoked by + bbdb-change-hook, and triggering spam-clear-cache of 'spam-use-BBDB + (spam-check-BBDB): check and use the caches, if + spam-cache-lookups is on + remove superfluous (provide) + 2004-01-06 Reiner Steib * gnus-art.el (gnus-treat-ansi-sequences): Changed default. diff --git a/lisp/spam.el b/lisp/spam.el index dc3472de9..c1e8969dd 100644 --- a/lisp/spam.el +++ b/lisp/spam.el @@ -426,6 +426,14 @@ spamoracle database." "Msx" gnus-summary-mark-as-spam "\M-d" gnus-summary-mark-as-spam) +(defvar spam-cache-lookups nil + "Whether spam.el will try to cache lookups using spam-caches.") + +(defvar spam-caches (make-hash-table + :size 10 + :test 'equal) + "Cache of spam detection entries.") + (defvar spam-old-ham-articles nil "List of old ham articles, generated when a group is entered.") @@ -440,6 +448,9 @@ spamoracle database." finds ham or spam.") ;; convenience functions +(defun spam-clear-cache (symbol) + (remhash symbol spam-caches)) + (defun spam-xor (a b) "Logical exclusive `or'." (and (or a b) (not (and a b)))) @@ -914,9 +925,14 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details." (let* ((group gnus-newsgroup-name) (autodetect (gnus-parameter-spam-autodetect group)) (methods (gnus-parameter-spam-autodetect-methods group)) - (first-method (nth 0 methods))) - (when (and autodetect - (not (equal first-method 'none))) + (first-method (nth 0 methods)) + (articles (if spam-autodetect-recheck-messages + gnus-newsgroup-articles + gnus-newsgroup-unseen)) + (spam-cache-lookups (< 2 (length articles)))) + + (when (and autodetect + (not (equal first-method 'none))) (mapcar (lambda (article) (let ((id (spam-fetch-field-message-id-fast article)) @@ -942,16 +958,14 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details." (when (zerop (gnus-registry-group-count id)) (gnus-registry-add-group id group subject sender)) - + (spam-log-processing-to-registry id 'incoming split-return spam-split-last-successful-check group)))))) - (if spam-autodetect-recheck-messages - gnus-newsgroup-articles - gnus-newsgroup-unseen))))) + articles)))) (defvar spam-registration-functions ;; first the ham register, second the spam register function @@ -1270,6 +1284,12 @@ functions") (require 'bbdb) (require 'bbdb-com) + ;; when the BBDB changes, we want to clear out our cache + (defun spam-clear-cache-BBDB (&rest immaterial) + (spam-clear-cache 'spam-use-BBDB)) + + (add-hook 'bbdb-change-hook 'spam-clear-cache-BBDB) + (defun spam-enter-ham-BBDB (addresses &optional remove) "Enter an address into the BBDB; implies ham (non-spam) sender" (dolist (from addresses) @@ -1308,10 +1328,21 @@ functions") (let ((who (nnmail-fetch-field "from")) (spam-split-group (if spam-split-symbolic-return 'spam - spam-split-group))) + spam-split-group)) + bbdb-cache) + + (when spam-cache-lookups + (setq bbdb-cache (gethash 'spam-use-BBDB spam-caches)) + (unless bbdb-cache + (setq bbdb-cache (bbdb-hashtable)) + (puthash 'spam-use-BBDB bbdb-cache spam-caches))) + (when who (setq who (nth 1 (gnus-extract-address-components who))) - (if (bbdb-search-simple nil who) + (if + (if spam-cache-lookups + (bbdb-gethash who bbdb-cache) + (bbdb-search-simple nil who)) t (if spam-use-BBDB-exclusive spam-split-group @@ -1319,6 +1350,8 @@ functions") (file-error (progn (defalias 'bbdb-search-simple 'ignore) + (defalias 'bbdb-hashtable 'ignore) + (defalias 'bbdb-gethash 'ignore) (defalias 'spam-check-BBDB 'ignore) (defalias 'spam-BBDB-register-routine 'ignore) (defalias 'spam-enter-ham-BBDB 'ignore) @@ -1810,7 +1843,3 @@ REMOVE not nil, remove the ADDRESSES." (provide 'spam) ;;; spam.el ends here. - -(provide 'spam) - -;;; spam.el ends here -- 2.34.1