* elmo-shimbun.el (elmo-shimbun-check-interval): New user option.
authorteranisi <teranisi>
Mon, 23 Apr 2001 06:20:39 +0000 (06:20 +0000)
committerteranisi <teranisi>
Mon, 23 Apr 2001 06:20:39 +0000 (06:20 +0000)
(elmo-shimbun-headers-cache): New internal variable.
(elmo-shimbun-headers-cache-header-list): New inline function.
(elmo-shimbun-headers-cache-set-header-list): Ditto.
(elmo-shimbun-headers-cache-header-hash): Ditto.
(elmo-shimbun-headers-cache-set-header-hash): Ditto.
(elmo-shimbun-headers-cache-last-check): Ditto.
(elmo-shimbun-headers-cache-set-last-check): Ditto.
(elmo-shimbun-lapse-seconds): Ditto.
(elmo-shimbun-headers-cache-check-p): Ditto.
(elmo-shimbun-get-headers): New function.
(elmo-folder-open-internal): Call it.
(elmo-quit): Define (Clear headers-cache).

* wl-summary.el (wl-summary-set-message-buffer-or-redisplay):
Check wl-message-buffer lives before set-buffer.

elmo/ChangeLog
elmo/elmo-shimbun.el
wl/ChangeLog
wl/wl-summary.el

index ba9dbbd..a034169 100644 (file)
@@ -1,3 +1,19 @@
+2001-04-23  Yuuichi Teranishi  <teranisi@gohome.org>
+
+       * elmo-shimbun.el (elmo-shimbun-check-interval): New user option.
+       (elmo-shimbun-headers-cache): New internal variable.
+       (elmo-shimbun-headers-cache-header-list): New inline function.
+       (elmo-shimbun-headers-cache-set-header-list): Ditto.
+       (elmo-shimbun-headers-cache-header-hash): Ditto.
+       (elmo-shimbun-headers-cache-set-header-hash): Ditto.
+       (elmo-shimbun-headers-cache-last-check): Ditto.
+       (elmo-shimbun-headers-cache-set-last-check): Ditto.
+       (elmo-shimbun-lapse-seconds): Ditto.
+       (elmo-shimbun-headers-cache-check-p): Ditto.
+       (elmo-shimbun-get-headers): New function.
+       (elmo-folder-open-internal): Call it.
+       (elmo-quit): Define (Clear headers-cache).
+
 2001-04-18  Yuuichi Teranishi  <teranisi@gohome.org>
 
        * elmo-nntp.el (elmo-folder-initialize): Fixed typo (folder->name).
index b16c582..11d3169 100644 (file)
 (require 'elmo-map)
 (require 'shimbun)
 
+(defcustom elmo-shimbun-check-interval 60
+  "*Check interval for shimbun."
+  :type 'integer
+  :group 'elmo)
+
+;; Internal variable.
+;; A list of elements like:
+;; ("server.group" . [header-list header-hash last-check]).
+(defvar elmo-shimbun-headers-cache nil)
+
 (eval-and-compile
   (luna-define-class elmo-shimbun-folder
                     (elmo-map-folder) (shimbun headers header-hash group))
   (luna-define-internal-accessors 'elmo-shimbun-folder))
 
+(defsubst elmo-shimbun-headers-cache-header-list (entry)
+  (aref entry 0))
+
+(defsubst elmo-shimbun-headers-cache-set-header-list (entry list)
+  (aset entry 0 list))
+
+(defsubst elmo-shimbun-headers-cache-header-hash (entry)
+  (aref entry 1))
+
+(defsubst elmo-shimbun-headers-cache-set-header-hash (entry hash)
+  (aset entry 1 hash))
+
+(defsubst elmo-shimbun-headers-cache-last-check (entry)
+  (aref entry 2))
+
+(defsubst elmo-shimbun-headers-cache-set-last-check (entry time)
+  (aset entry 2 time))
+
+(defsubst elmo-shimbun-lapse-seconds (time)
+  (let ((now (current-time)))
+    (+ (* (- (car now) (car time)) 65536)
+       (- (nth 1 now) (nth 1 time)))))
+
+(defsubst elmo-shimbun-headers-cache-check-p (cache)
+  (or (null (elmo-shimbun-headers-cache-last-check cache))
+      (and (elmo-shimbun-headers-cache-last-check cache)
+          (> (elmo-shimbun-lapse-seconds
+              (elmo-shimbun-headers-cache-last-check cache))
+             elmo-shimbun-check-interval))))
+
+(defun elmo-shimbun-get-headers (folder)
+  (shimbun-open-group
+   (elmo-shimbun-folder-shimbun-internal folder)
+   (elmo-shimbun-folder-group-internal folder))
+  (let* ((shimbun (elmo-shimbun-folder-shimbun-internal folder))
+        (key (concat (shimbun-server-internal shimbun)
+                     "." (shimbun-current-group-internal shimbun)))
+        (elmo-hash-minimum-size 0)
+        entry headers hash done)
+    (if (setq entry (cdr (assoc key elmo-shimbun-headers-cache)))
+       (unless (elmo-shimbun-headers-cache-check-p entry)
+         (elmo-shimbun-folder-set-headers-internal
+          folder
+          (elmo-shimbun-headers-cache-header-list entry))
+         (elmo-shimbun-folder-set-header-hash-internal
+          folder
+          (elmo-shimbun-headers-cache-header-hash entry))
+         (elmo-shimbun-headers-cache-header-list entry)
+         (setq done t)))
+    (unless done
+      (setq headers
+           (elmo-shimbun-folder-set-headers-internal
+            folder (shimbun-headers
+                    (elmo-shimbun-folder-shimbun-internal folder))))
+      (setq hash
+           (elmo-shimbun-folder-set-header-hash-internal
+            folder
+            (elmo-make-hash
+             (length (elmo-shimbun-folder-headers-internal folder)))))
+      ;; Set up header hash.
+      (dolist (header (elmo-shimbun-folder-headers-internal folder))
+       (elmo-set-hash-val
+        (shimbun-header-id header) header
+        (elmo-shimbun-folder-header-hash-internal folder)))
+      (if entry
+         (progn
+           (elmo-shimbun-headers-cache-set-header-list entry headers)
+           (elmo-shimbun-headers-cache-set-header-hash entry hash)
+           (elmo-shimbun-headers-cache-set-last-check entry (current-time)))
+       (setq elmo-shimbun-headers-cache
+             (cons (cons key (vector headers hash (current-time)))
+                   elmo-shimbun-headers-cache))))))
+
 (luna-define-method elmo-folder-initialize ((folder
                                             elmo-shimbun-folder)
                                            name)
 (luna-define-method elmo-folder-open-internal :before ((folder
                                                        elmo-shimbun-folder))
   (when (elmo-folder-plugged-p folder)
-    (shimbun-open-group
-     (elmo-shimbun-folder-shimbun-internal folder)
-     (elmo-shimbun-folder-group-internal folder))
-    (elmo-shimbun-folder-set-headers-internal
-     folder (shimbun-headers
-            (elmo-shimbun-folder-shimbun-internal folder)))
-    (elmo-shimbun-folder-set-header-hash-internal
-     folder
-     (elmo-make-hash (length (elmo-shimbun-folder-headers-internal folder))))
-    ;; Set up header hash.
-    (dolist (header (elmo-shimbun-folder-headers-internal folder))
-      (elmo-set-hash-val
-       (shimbun-header-id header) header
-       (elmo-shimbun-folder-header-hash-internal folder)))))
+    (elmo-shimbun-get-headers folder)))
 
 (luna-define-method elmo-folder-close-internal :after ((folder
                                                        elmo-shimbun-folder))
 (luna-define-method elmo-folder-mark-as-read ((folder elmo-shimbun-folder)
                                              numbers)
   t)
-  
+
+(luna-define-method elmo-quit ((folder elmo-shimbun-folder))
+  (setq elmo-shimbun-headers-cache nil))
 (require 'product)
 (product-provide (provide 'elmo-shimbun) (require 'elmo-version))
 
index 116fc41..582b5c0 100644 (file)
@@ -1,3 +1,8 @@
+2001-04-23  Yuuichi Teranishi  <teranisi@gohome.org>
+
+       * wl-summary.el (wl-summary-set-message-buffer-or-redisplay):
+       Check wl-message-buffer lives before set-buffer.
+
 2001-04-07  Masahiro MURATA  <muse@ba2.so-net.ne.jp>
 
        * wl-expire.el (wl-summary-expire): Fixed problem that do not expire
index 92b5683..94534bd 100644 (file)
@@ -4570,7 +4570,8 @@ Return t if message exists."
       (if (wl-summary-no-mime-p folder)
          (wl-summary-redisplay-no-mime folder number)
        (wl-summary-redisplay-internal folder number))
-      (set-buffer wl-message-buffer)
+      (when (buffer-live-p wl-message-buffer)
+       (set-buffer wl-message-buffer))
       nil)))
 
 (defun wl-summary-target-mark-forward (&optional arg)