]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/debbugs/debbugs.el
Make debbugs-newest-bugs more robust
[gnu-emacs-elpa] / packages / debbugs / debbugs.el
index c3d230732a3ba9fd6dc8c7f8222534a91b9606fe..8221c37230885f9abb745105c51d2b2d95ded918 100644 (file)
@@ -242,7 +242,45 @@ patch:
 
 (defun debbugs-newest-bugs (amount)
   "Return the list of bug numbers, according to AMOUNT (a number) latest bugs."
-  (sort (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<))
+  (if (= amount 1)
+      ;; We cache it as bug "0" in `debbugs-cache-data'.
+      (let ((status (gethash 0 debbugs-cache-data)))
+       (unless (and
+                status
+                (or
+                 (null debbugs-cache-expiry)
+                 (and
+                  (natnump debbugs-cache-expiry)
+                  (> (cdr (assoc 'cache_time status))
+                     (- (float-time) debbugs-cache-expiry)))))
+         ;; Due to `debbugs-gnu-completion-table', this function
+         ;; could be called in rapid sequence.  We cache temporarily
+         ;; the value nil, therefore.
+         (when (natnump debbugs-cache-expiry)
+           (puthash
+            0
+            (list (cons 'cache_time (1+ (- (float-time) debbugs-cache-expiry)))
+                  (list 'newest_bug))
+            debbugs-cache-data))
+         ;; Compute the value.
+         (setq
+          status
+          (list
+           (cons 'cache_time (float-time))
+           (cons 'newest_bug
+                 (caar
+                  (soap-invoke
+                   debbugs-wsdl debbugs-port "newest_bugs" amount)))))
+
+         ;; Cache it.
+         (when (or (null debbugs-cache-expiry) (natnump debbugs-cache-expiry))
+           (puthash 0 status debbugs-cache-data)))
+
+       ;; Return the value, as list.
+       (list (cdr (assoc 'newest_bug status))))
+
+    (sort
+     (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<)))
 
 (defun debbugs-convert-soap-value-to-string (string-value)
   "If STRING-VALUE is unibyte, decode its contents as a UTF-8 string.
@@ -359,7 +397,7 @@ Example:
                      (and
                       (natnump debbugs-cache-expiry)
                       (> (cdr (assoc 'cache_time status))
-                         (- (float-time)) debbugs-cache-expiry))))
+                         (- (float-time) debbugs-cache-expiry)))))
                    (progn
                      (setq cached-bugs (append cached-bugs (list status)))
                      nil)
@@ -430,7 +468,7 @@ Example:
            (when (stringp (cdr y))
              (setcdr y (split-string (cdr y) ",\\| " t))))
          ;; Cache the result, and return.
-         (if (and debbugs-cache-expiry (natnump debbugs-cache-expiry))
+         (if (or (null debbugs-cache-expiry) (natnump debbugs-cache-expiry))
              (puthash
               (cdr (assoc 'key x))
               ;; Put also a time stamp.