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:
Brit Butler 2014-05-16 11:07:36 -04:00
parent f58c265fb7
commit 6283d63331

View file

@ -1,13 +1,18 @@
(in-package :coleslaw) (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 () (defclass index ()
((slug :initarg :slug :reader index-slug) ((slug :initarg :slug :reader index-slug)
(title :initarg :title :reader title-of) (title :initarg :title :reader title-of)
(content :initarg :content :reader index-content))) (content :initarg :content :reader index-content)))
(defmethod render ((object index) &key prev next) (defmethod render ((object index) &key prev next)
(funcall (theme-fn 'index) (list :tags (all-tags) (funcall (theme-fn 'index) (list :tags *all-tags*
:months (all-months) :months *all-months*
:config *config* :config *config*
:index object :index object
:prev prev :prev prev
@ -18,6 +23,7 @@
(defclass tag-index (index) ()) (defclass tag-index (index) ())
(defmethod discover ((doc-type (eql (find-class 'tag-index)))) (defmethod discover ((doc-type (eql (find-class 'tag-index))))
(setf *all-tags* (all-tags))
(let ((content (by-date (find-all 'post)))) (let ((content (by-date (find-all 'post))))
(dolist (tag (all-tags)) (dolist (tag (all-tags))
(add-document (index-by-tag tag content))))) (add-document (index-by-tag tag content)))))
@ -37,8 +43,9 @@
(defclass month-index (index) ()) (defclass month-index (index) ())
(defmethod discover ((doc-type (eql (find-class 'month-index)))) (defmethod discover ((doc-type (eql (find-class 'month-index))))
(setf *all-months* (all-months))
(let ((content (by-date (find-all 'post)))) (let ((content (by-date (find-all 'post))))
(dolist (month (all-months)) (dolist (month *all-months*)
(add-document (index-by-month month content))))) (add-document (index-by-month month content)))))
(defun index-by-month (month content) (defun index-by-month (month content)