Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
6283d63331
1 muutettua tiedostoa jossa 10 lisäystä ja 3 poistoa
  1. 10 3
      src/indexes.lisp

+ 10 - 3
src/indexes.lisp

1
 (in-package :coleslaw)
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
 (defclass index ()
8
 (defclass index ()
4
   ((slug :initarg :slug :reader index-slug)
9
   ((slug :initarg :slug :reader index-slug)
5
    (title :initarg :title :reader title-of)
10
    (title :initarg :title :reader title-of)
6
    (content :initarg :content :reader index-content)))
11
    (content :initarg :content :reader index-content)))
7
 
12
 
8
 (defmethod render ((object index) &key prev next)
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
                                    :config *config*
16
                                    :config *config*
12
                                    :index object
17
                                    :index object
13
                                    :prev prev
18
                                    :prev prev
18
 (defclass tag-index (index) ())
23
 (defclass tag-index (index) ())
19
 
24
 
20
 (defmethod discover ((doc-type (eql (find-class 'tag-index))))
25
 (defmethod discover ((doc-type (eql (find-class 'tag-index))))
26
+  (setf *all-tags* (all-tags))
21
   (let ((content (by-date (find-all 'post))))
27
   (let ((content (by-date (find-all 'post))))
22
     (dolist (tag (all-tags))
28
     (dolist (tag (all-tags))
23
       (add-document (index-by-tag tag content)))))
29
       (add-document (index-by-tag tag content)))))
37
 (defclass month-index (index) ())
43
 (defclass month-index (index) ())
38
 
44
 
39
 (defmethod discover ((doc-type (eql (find-class 'month-index))))
45
 (defmethod discover ((doc-type (eql (find-class 'month-index))))
46
+  (setf *all-months* (all-months))
40
   (let ((content (by-date (find-all 'post))))
47
   (let ((content (by-date (find-all 'post))))
41
-    (dolist (month (all-months))
48
+    (dolist (month *all-months*)
42
       (add-document (index-by-month month content)))))
49
       (add-document (index-by-month month content)))))
43
 
50
 
44
 (defun index-by-month (month content)
51
 (defun index-by-month (month content)