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.
This commit is contained in:
parent
f58c265fb7
commit
6283d63331
1 changed files with 10 additions and 3 deletions
|
@ -1,13 +1,18 @@
|
|||
(in-package :coleslaw)
|
||||
|
||||
(defvar *all-months* nil
|
||||
"The list of months in which content was authored.")
|
||||
(defvar *all-tags* nil
|
||||
"The list of tags which content has been tagged with.")
|
||||
|
||||
(defclass index ()
|
||||
((slug :initarg :slug :reader index-slug)
|
||||
(title :initarg :title :reader title-of)
|
||||
(content :initarg :content :reader index-content)))
|
||||
|
||||
(defmethod render ((object index) &key prev next)
|
||||
(funcall (theme-fn 'index) (list :tags (all-tags)
|
||||
:months (all-months)
|
||||
(funcall (theme-fn 'index) (list :tags *all-tags*
|
||||
:months *all-months*
|
||||
:config *config*
|
||||
:index object
|
||||
:prev prev
|
||||
|
@ -18,6 +23,7 @@
|
|||
(defclass tag-index (index) ())
|
||||
|
||||
(defmethod discover ((doc-type (eql (find-class 'tag-index))))
|
||||
(setf *all-tags* (all-tags))
|
||||
(let ((content (by-date (find-all 'post))))
|
||||
(dolist (tag (all-tags))
|
||||
(add-document (index-by-tag tag content)))))
|
||||
|
@ -37,8 +43,9 @@
|
|||
(defclass month-index (index) ())
|
||||
|
||||
(defmethod discover ((doc-type (eql (find-class 'month-index))))
|
||||
(setf *all-months* (all-months))
|
||||
(let ((content (by-date (find-all 'post))))
|
||||
(dolist (month (all-months))
|
||||
(dolist (month *all-months*)
|
||||
(add-document (index-by-month month content)))))
|
||||
|
||||
(defun index-by-month (month content)
|
||||
|
|
Loading…
Add table
Reference in a new issue