From: Lars Magne Ingebrigtsen Date: Sat, 26 Jan 2002 11:30:34 +0000 (+0000) Subject: * gnus-agent.el (gnus-agent-load-alist): Use new caching X-Git-Url: https://cgit.sxemacs.org/?a=commitdiff_plain;h=860cba8e2ef2c6295479fb91a9f5b534721dc37f;p=gnus * 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. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7f4d8dc63..f064aec4e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,17 @@ 2002-01-26 Lars Magne Ingebrigtsen + * 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 diff --git a/lisp/gnus-agent.el b/lisp/gnus-agent.el index bb7b12f78..a7bbe9e3e 100644 --- a/lisp/gnus-agent.el +++ b/lisp/gnus-agent.el @@ -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." diff --git a/lisp/gnus-util.el b/lisp/gnus-util.el index 610ad5bc0..3a42cadfe 100644 --- a/lisp/gnus-util.el +++ b/lisp/gnus-util.el @@ -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 diff --git a/lisp/nnagent.el b/lisp/nnagent.el index 94371c221..e22591ed9 100644 --- a/lisp/nnagent.el +++ b/lisp/nnagent.el @@ -137,7 +137,7 @@ (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 diff --git a/lisp/nnheader.el b/lisp/nnheader.el index c3491b34a..a3b145a53 100644 --- a/lisp/nnheader.el +++ b/lisp/nnheader.el @@ -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))