* [PATCH] Only load .spam-stat.el if needed
@ 2004-06-01 22:32 Nelson Ferreira
0 siblings, 0 replies; only message in thread
From: Nelson Ferreira @ 2004-06-01 22:32 UTC (permalink / raw)
I noticed a huge delay on every news update because of spam-stat-load,
which had to load everytime a (now) huge file.
This patch attempts to only load when the file was not loaded before,
or somehow it changed on disk:
Please use at will.
diff -u -r7.16 spam-stat.el
--- spam-stat.el 20 May 2004 08:02:41 -0000 7.16
+++ spam-stat.el 1 Jun 2004 22:30:15 -0000
@@ -185,6 +185,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)
@@ -400,14 +403,24 @@
(spam-stat-bad entry))))
spam-stat)
(insert ")))"))))
- (setq spam-stat-dirty nil)))
+ (setq spam-stat-dirty nil)
+ (setq 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 (null spam-stat-last-saved-at)
+ (not (boundp '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)
+ (setq 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'.
--
Nelson Ferreira
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-06-01 22:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-01 22:32 [PATCH] Only load .spam-stat.el if needed 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).