Kaynağa Gözat

A little performance hack for faster compiles.

We were generating the complete list of tags and months on every
index render. Now the data is computed once during content load
and cached in a global for the remainder of the compilation process.
20% reduction in compile-time for my 430-post blog.
Brit Butler 11 yıl önce
ebeveyn
işleme
6283d63331
1 değiştirilmiş dosya ile 10 ekleme ve 3 silme
  1. 10 3
      src/indexes.lisp

+ 10 - 3
src/indexes.lisp

@@ -1,13 +1,18 @@
1 1
 (in-package :coleslaw)
2 2
 
3
+(defvar *all-months* nil
4
+  "The list of months in which content was authored.")
5
+(defvar *all-tags* nil
6
+  "The list of tags which content has been tagged with.")
7
+
3 8
 (defclass index ()
4 9
   ((slug :initarg :slug :reader index-slug)
5 10
    (title :initarg :title :reader title-of)
6 11
    (content :initarg :content :reader index-content)))
7 12
 
8 13
 (defmethod render ((object index) &key prev next)
9
-  (funcall (theme-fn 'index) (list :tags (all-tags)
10
-                                   :months (all-months)
14
+  (funcall (theme-fn 'index) (list :tags *all-tags*
15
+                                   :months *all-months*
11 16
                                    :config *config*
12 17
                                    :index object
13 18
                                    :prev prev
@@ -18,6 +23,7 @@
18 23
 (defclass tag-index (index) ())
19 24
 
20 25
 (defmethod discover ((doc-type (eql (find-class 'tag-index))))
26
+  (setf *all-tags* (all-tags))
21 27
   (let ((content (by-date (find-all 'post))))
22 28
     (dolist (tag (all-tags))
23 29
       (add-document (index-by-tag tag content)))))
@@ -37,8 +43,9 @@
37 43
 (defclass month-index (index) ())
38 44
 
39 45
 (defmethod discover ((doc-type (eql (find-class 'month-index))))
46
+  (setf *all-months* (all-months))
40 47
   (let ((content (by-date (find-all 'post))))
41
-    (dolist (month (all-months))
48
+    (dolist (month *all-months*)
42 49
       (add-document (index-by-month month content)))))
43 50
 
44 51
 (defun index-by-month (month content)