Gnus development mailing list
 help / color / mirror / Atom feed
* [PATCH] Load spam-stat hashtable only when there are changes in the disk file
@ 2004-12-05 16:55 Nelson Ferreira
  2004-12-05 21:41 ` Nelson Ferreira
  0 siblings, 1 reply; 2+ messages in thread
From: Nelson Ferreira @ 2004-12-05 16:55 UTC (permalink / raw)
  Cc: emacs-devel

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


This patch prevents spam-stat from doing unnecessary loads of the
hashtable to memory.


2004-12-05  Nelson Ferreira  <nelson.ferreira@ieee.org>

	* spam-stat.el (spam-stat-save): Load the hashtable from disk only
	if there is no hashtable in memory or file modification time is
	newer than cached timestamp.



[-- Attachment #2: Load spam-stat hashtable only when there are changes in the disk file --]
[-- Type: text/x-patch, Size: 5233 bytes --]

Index: lisp/ChangeLog
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/ChangeLog,v
retrieving revision 7.554
diff -u -u -b -r7.554 ChangeLog
--- lisp/ChangeLog	3 Dec 2004 15:58:17 -0000	7.554
+++ lisp/ChangeLog	5 Dec 2004 16:52:53 -0000
@@ -1,3 +1,9 @@
+2004-12-05  Nelson Ferreira  <nelson.ferreira@ieee.org>
+
+	* spam-stat.el (spam-stat-save): Load the hashtable from disk only
+	if there is no hashtable in memory or file modification time is
+	newer than cached timestamp.
+
 2004-12-03  Reiner Steib  <Reiner.Steib@gmx.de>
 
 	* gnus-sum.el (gnus-summary-limit-to-recipient): Implement
@@ -161,7 +167,7 @@
 
 	* gnus-art.el (gnus-header-button-alist): Handle URLs in OpenPGP:
 	headers separately.
-	(gnus-button-openpgp): New function, inspired by Jochen Küpper
+	(gnus-button-openpgp): New function, inspired by Jochen Küpper
 	<jochen@fhi-berlin.mpg.de>.
 
 2004-11-14  Reiner Steib  <Reiner.Steib@gmx.de>
@@ -1881,7 +1887,7 @@
 	(spam-mark-new-messages-in-spam-group-as-spam): allow user to
 	disable assigning the spam-mark to new messages
 	(spam-ham-copy-or-move-routine): todo decleared twice (tiny
-	change).  From Adam Sjøgren <asjo@koldfront.dk>.
+	change).  From Adam Sjøgren <asjo@koldfront.dk>.
 
 2004-05-26  Katsumi Yamaoka  <yamaoka@jpl.org>
 
@@ -2021,7 +2027,7 @@
 	(spam-crm114-unregister-spam-routine)
 	(spam-crm114-register-ham-routine)
 	(spam-crm114-unregister-ham-routine): add CRM114 support.  From
-	asjo@koldfront.dk (Adam Sjøgren).
+	asjo@koldfront.dk (Adam Sjøgren).
 
 	* gnus.el: added spam-use-crm114
 
@@ -2462,7 +2468,7 @@
 2004-04-22  Teodor Zlatanov  <tzz@lifelogs.com>
 
 	From Dan Christensen <jdc@uwo.ca>, asjo@koldfront.dk (Adam
-	Sjøgren), Wes Hardaker <wes@hardakers.net>, and Michael Shields
+	Sjøgren), Wes Hardaker <wes@hardakers.net>, and Michael Shields
 	<shields@msrl.com>:
 	
 	* spam.el (spam-necessary-extra-headers): get the extra headers we
@@ -2480,7 +2486,7 @@
 2004-04-21  Teodor Zlatanov  <tzz@lifelogs.com>
 
 	* spam.el (spam-summary-prepare-exit): logic and message fix.
-	Reported by bojohan+news@dd.chalmers.se (Johan Bockgård).
+	Reported by bojohan+news@dd.chalmers.se (Johan Bockgård).
 
 2004-04-17  Jesper Harder  <harder@ifa.au.dk>
 
@@ -3625,7 +3631,7 @@
 
 	* gnus-score.el (gnus-score-edit-all-score): Fix prototype.
 	Invoke gnus-score-mode.  Reported by
-	bojohan+news@dd.chalmers.se (Johan Bockgård).
+	bojohan+news@dd.chalmers.se (Johan Bockgård).
 
 	* gnus-range.el (gnus-compress-sequence): Doc fix.  Suggested by
 	Jim Blandy <jimb@redhat.com> (tiny change).
@@ -3982,7 +3988,7 @@
 
 	* nnheaderxm.el: Remove definition of run-at-time.
 
-2004-01-05  Karl Pflästerer  <sigurd@12move.de>
+2004-01-05  Karl Pflästerer  <sigurd@12move.de>
 
 	* mml.el (mml-minibuffer-read-disposition): Show attachment type
 	in prompt (tiny change)
Index: lisp/spam-stat.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/spam-stat.el,v
retrieving revision 7.19
diff -u -u -b -r7.19 spam-stat.el
--- lisp/spam-stat.el	2 Nov 2004 02:54:22 -0000	7.19
+++ lisp/spam-stat.el	5 Dec 2004 16:52:54 -0000
@@ -186,6 +186,9 @@
 this filter, re-training spam-stat with several thousand messages
 will start to take a very long time.")
 
+(defvar spam-stat-last-saved-at nil
+  "Time stamp of last change of spam-stat-file on this run")
+
 (defvar spam-stat-syntax-table
   (let ((table (copy-syntax-table text-mode-syntax-table)))
     (modify-syntax-entry ?- "w" table)
@@ -389,6 +392,7 @@
   (interactive "P")
   (when (or force spam-stat-dirty)
     (let ((coding-system-for-write spam-stat-coding-system))
+      (message "Saving %s..."  spam-stat-file)
       (with-temp-file spam-stat-file
 	(let ((standard-output (current-buffer))
 	      (font-lock-maximum-size 0))
@@ -401,14 +405,25 @@
 				  (spam-stat-bad entry))))
 		   spam-stat)
 	  (insert ")))"))))
-	(setq spam-stat-dirty nil)))
+    (message "Saved %s."  spam-stat-file)
+    (setq spam-stat-dirty nil
+          spam-stat-last-saved-at (nth 5 (file-attributes spam-stat-file)))))
 
 (defun spam-stat-load ()
   "Read the `spam-stat' hash table from disk."
   ;; TODO: maybe we should warn the user if spam-stat-dirty is t?
   (let ((coding-system-for-read spam-stat-coding-system))
-    (load-file spam-stat-file))
-  (setq spam-stat-dirty nil))
+    (cond (spam-stat-dirty (message "Spam stat not loaded: spam-stat-dirty t"))
+          ((or (not (boundp 'spam-stat-last-saved-at))
+               (null spam-stat-last-saved-at)
+               (not (equal spam-stat-last-saved-at
+                           (nth 5 (file-attributes spam-stat-file)))))
+           (progn 
+             (load-file spam-stat-file)
+             (setq spam-stat-dirty nil
+                   spam-stat-last-saved-at 
+                   (nth 5 (file-attributes spam-stat-file)))))
+          (t (message "Spam stat file not loaded: no change in disk..")))))
 
 (defun spam-stat-to-hash-table (entries)
   "Turn list ENTRIES into a hash table and store as `spam-stat'.

[-- Attachment #3: Type: text/plain, Size: 22 bytes --]



-- 
Nelson Ferreira

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

* Re: [PATCH] Load spam-stat hashtable only when there are changes in the disk file
  2004-12-05 16:55 [PATCH] Load spam-stat hashtable only when there are changes in the disk file Nelson Ferreira
@ 2004-12-05 21:41 ` Nelson Ferreira
  0 siblings, 0 replies; 2+ messages in thread
From: Nelson Ferreira @ 2004-12-05 21:41 UTC (permalink / raw)
  Cc: emacs-devel

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

"Nelson" == Nelson Ferreira <nelson.ferreira@verizon.net> writes:

    Nelson> This patch prevents spam-stat from doing unnecessary loads
    Nelson> of the hashtable to memory.

    Nelson> 2004-12-05 Nelson Ferreira <nelson.ferreira@ieee.org>

    Nelson> * spam-stat.el (spam-stat-save): Load the hashtable from
    Nelson> 	  disk only
    Nelson> 	if there is no hashtable in memory or file
    Nelson> 	modification time is newer than cached timestamp.

My coding-system settings made the ChangeLog diff to ruin the
iso-2022-7 coding. Here is a correct patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Load spam-stat hashtable only when there are changes in the disk file --]
[-- Type: text/x-patch, Size: 2872 bytes --]

Index: lisp/ChangeLog
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/ChangeLog,v
retrieving revision 7.554
diff -u -u -b -r7.554 ChangeLog
--- lisp/ChangeLog	3 Dec 2004 15:58:17 -0000	7.554
+++ lisp/ChangeLog	5 Dec 2004 21:40:55 -0000
@@ -1,3 +1,9 @@
+2004-12-05  Nelson Ferreira  <nelson.ferreira@ieee.org>
+
+	* spam-stat.el (spam-stat-save): Load the hashtable from disk only
+	if there is no hashtable in memory or file modification time is
+	newer than cached timestamp.
+
 2004-12-03  Reiner Steib  <Reiner.Steib@gmx.de>
 
 	* gnus-sum.el (gnus-summary-limit-to-recipient): Implement
Index: lisp/spam-stat.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/spam-stat.el,v
retrieving revision 7.19
diff -u -u -b -r7.19 spam-stat.el
--- lisp/spam-stat.el	2 Nov 2004 02:54:22 -0000	7.19
+++ lisp/spam-stat.el	5 Dec 2004 21:40:55 -0000
@@ -186,6 +186,9 @@
 this filter, re-training spam-stat with several thousand messages
 will start to take a very long time.")
 
+(defvar spam-stat-last-saved-at nil
+  "Time stamp of last change of spam-stat-file on this run")
+
 (defvar spam-stat-syntax-table
   (let ((table (copy-syntax-table text-mode-syntax-table)))
     (modify-syntax-entry ?- "w" table)
@@ -389,6 +392,7 @@
   (interactive "P")
   (when (or force spam-stat-dirty)
     (let ((coding-system-for-write spam-stat-coding-system))
+      (message "Saving %s..."  spam-stat-file)
       (with-temp-file spam-stat-file
 	(let ((standard-output (current-buffer))
 	      (font-lock-maximum-size 0))
@@ -401,14 +405,25 @@
 				  (spam-stat-bad entry))))
 		   spam-stat)
 	  (insert ")))"))))
-	(setq spam-stat-dirty nil)))
+    (message "Saved %s."  spam-stat-file)
+    (setq spam-stat-dirty nil
+          spam-stat-last-saved-at (nth 5 (file-attributes spam-stat-file)))))
 
 (defun spam-stat-load ()
   "Read the `spam-stat' hash table from disk."
   ;; TODO: maybe we should warn the user if spam-stat-dirty is t?
   (let ((coding-system-for-read spam-stat-coding-system))
-    (load-file spam-stat-file))
-  (setq spam-stat-dirty nil))
+    (cond (spam-stat-dirty (message "Spam stat not loaded: spam-stat-dirty t"))
+          ((or (not (boundp 'spam-stat-last-saved-at))
+               (null spam-stat-last-saved-at)
+               (not (equal spam-stat-last-saved-at
+                           (nth 5 (file-attributes spam-stat-file)))))
+           (progn 
+             (load-file spam-stat-file)
+             (setq spam-stat-dirty nil
+                   spam-stat-last-saved-at 
+                   (nth 5 (file-attributes spam-stat-file)))))
+          (t (message "Spam stat file not loaded: no change in disk..")))))
 
 (defun spam-stat-to-hash-table (entries)
   "Turn list ENTRIES into a hash table and store as `spam-stat'.

[-- Attachment #3: Type: text/plain, Size: 22 bytes --]



-- 
Nelson Ferreira

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

end of thread, other threads:[~2004-12-05 21:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-05 16:55 [PATCH] Load spam-stat hashtable only when there are changes in the disk file Nelson Ferreira
2004-12-05 21:41 ` Nelson Ferreira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).