* gnus-agent.el (gnus-agent-load-alist): Use new caching
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Sat, 26 Jan 2002 11:30:34 +0000 (11:30 +0000)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Sat, 26 Jan 2002 11:30:34 +0000 (11:30 +0000)
function.

* gnus-util.el (gnus-cache-file-contents): New function.

* gnus-agent.el (gnus-agent-file-loading-cache): New variable.
(gnus-agent-load-alist): Use it.

* nnagent.el (nnagent-retrieve-headers): Use optimized function.

* nnheader.el (nnheader-insert-nov-file): New function.

lisp/ChangeLog
lisp/gnus-agent.el
lisp/gnus-util.el
lisp/nnagent.el
lisp/nnheader.el

index 7f4d8dc..f064aec 100644 (file)
@@ -1,5 +1,17 @@
 2002-01-26  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
+       * gnus-agent.el (gnus-agent-load-alist): Use new caching
+       function. 
+
+       * gnus-util.el (gnus-cache-file-contents): New function.
+
+       * gnus-agent.el (gnus-agent-file-loading-cache): New variable.
+       (gnus-agent-load-alist): Use it.
+
+       * nnagent.el (nnagent-retrieve-headers): Use optimized function. 
+
+       * nnheader.el (nnheader-insert-nov-file): New function.
+
        * gnus-util.el (gnus-parse-without-error): Correct the loop. 
 
        * gnus-sum.el (gnus-dependencies-add-header): Use in-reply-to if
index bb7b12f..a7bbe9e 100644 (file)
@@ -143,6 +143,7 @@ If this is `ask' the hook will query the user."
 (defvar gnus-agent-file-name nil)
 (defvar gnus-agent-send-mail-function nil)
 (defvar gnus-agent-file-coding-system 'raw-text)
+(defvar gnus-agent-file-loading-cache nil)
 
 ;; Dynamic variables
 (defvar gnus-headers)
@@ -1115,11 +1116,14 @@ the actual number of articles toggled is returned."
 
 (defun gnus-agent-load-alist (group &optional dir)
   "Load the article-state alist for GROUP."
+  (let ((file ))
   (setq gnus-agent-article-alist
-       (gnus-agent-read-file
+       (gnus-cache-file-contents
         (if dir
-            (expand-file-name ".agentview" dir)
-          (gnus-agent-article-name ".agentview" group)))))
+                 (expand-file-name ".agentview" dir)
+               (gnus-agent-article-name ".agentview" group))
+        'gnus-agent-file-loading-cache
+        'gnus-agent-read-file))))
 
 (defun gnus-agent-save-alist (group &optional articles state dir)
   "Save the article-state alist for GROUP."
index 610ad5b..3a42cad 100644 (file)
@@ -1274,6 +1274,19 @@ SPEC is a predicate specifier that contains stuff like `or', `and',
                    (count-lines (point-min) (point)))
        (forward-line 1)))))
 
+(defun gnus-cache-file-contents (file variable function)
+  "Cache the contents of FILE in VARIABLE.  The contents come from FUNCTION."
+  (let ((time (nth 5 (file-attributes file)))
+       contents value)
+    (if (or (null (setq value (symbol-value variable)))
+           (not (equalp (car value) file))
+           (not (equalp (nth 1 value) time)))
+       (progn
+         (setq contents (funcall function file))
+         (set variable (list file time contents))
+         contents)
+      (nth 2 value))))
+
 (provide 'gnus-util)
 
 ;;; gnus-util.el ends here
index 94371c2..e22591e 100644 (file)
                                      (mapcar 'car gnus-agent-article-alist)))
       (set-buffer nntp-server-buffer)
       (erase-buffer)
-      (nnheader-insert-file-contents file)
+      (nnheader-insert-nov-file file (car articles))
       (goto-char (point-min))
       (gnus-parse-without-error
        (while arts
index c3491b3..a3b145a 100644 (file)
@@ -875,6 +875,24 @@ find-file-hooks, etc.
   (let ((coding-system-for-read nnheader-file-coding-system))
     (mm-insert-file-contents filename visit beg end replace)))
 
+(defun nnheader-insert-nov-file (file first)
+  (let ((size (nth 7 (file-attributes file))))
+    (if (< size 4096)
+       ;; If the file is small, we just load it.
+       (nnheader-insert-file-contents file)
+      ;; We start on the assumption that FIRST is pretty recent.  If
+      ;; not, we just insert the rest of the file as well.
+      (let (current)
+       (nnheader-insert-file-contents file nil (- size 8192) size)
+       (goto-char (point-min))
+       (delete-region (point) (or (search-forward "\n" nil 'move) (point)))
+       (setq current (ignore-errors (read (current-buffer))))
+       (if (and (numberp current)
+                (< current first))
+           t
+         (delete-region (point-min) (point-max))
+         (nnheader-insert-file-contents file))))))
+
 (defun nnheader-find-file-noselect (&rest args)
   (let ((format-alist nil)
        (auto-mode-alist (mm-auto-mode-alist))