Bläddra i källkod

New pass at "incremental" compilation. See now, isn't that better?

Brit Butler 11 år sedan
förälder
incheckning
bed63d2156
2 ändrade filer med 23 tillägg och 87 borttagningar
  1. 5 1
      docs/hacking.md
  2. 18 86
      plugins/incremental.lisp

+ 5 - 1
docs/hacking.md

@@ -134,7 +134,7 @@ be seamlessly picked up by *coleslaw* and included on the rendered site.
134 134
 All current Content Types and Indexes implement the protocol faithfully.
135 135
 It consists of 2 "class" methods, 2 instance methods, and an invariant.
136 136
 
137
-There are also 4 helper functions provided that should prove useful in
137
+There are also 5 helper functions provided that should prove useful in
138 138
 implementing new content types.
139 139
 
140 140
 
@@ -191,6 +191,10 @@ eql-specializing on the class, e.g.
191 191
   unique. Such a hash collision represents content on the site being
192 192
   shadowed/overwritten. This should be used in your `discover` method.
193 193
 
194
+- `delete-document`: Remove a document from *coleslaw*'s in-memory
195
+  database. This is currently only used by the incremental compilation
196
+  plugin.
197
+
194 198
 - `write-document`: Write the document out to disk as HTML. It takes
195 199
   an optional template name and render-args to pass to the template.
196 200
   This should be used in your `publish` method.

+ 18 - 86
plugins/incremental.lisp

@@ -8,49 +8,38 @@
8 8
                           #:discover
9 9
                           #:get-updated-files
10 10
                           #:find-content-by-path
11
-                          #:find-all
12 11
                           #:add-document
13
-                          #:write-document
12
+                          #:delete-document
14 13
                           ;; Private
15 14
                           #:all-subclasses
15
+                          #:do-subclasses
16 16
                           #:construct
17
-                          #:rel-path
18
-                          #:index-content
19
-                          #:content-date
20
-                          #:content-tags
21
-                          #:tag-slug
22
-                          )
17
+                          #:rel-path)
23 18
   (:export #:enable))
24 19
 
25 20
 (in-package :coleslaw-incremental)
26 21
 
27
-;; KLUDGE: We currently never update the site for config changes.
28
-;; Examples to consider include changing the theme or domain of the site.
29
-;; Both would require full site recompiles. Consequently, it seems reasonable
30
-;; to expect that incremental plugin users:
31
-;;   A) have done a full build of their site
32
-;;   B) have a cl-store dump of the database at ~/.coleslaw.db
33
-;;      ^ we should provide a script or plugin just for this
34
-;;   C) move the original deployment to a location of their choice and set it
35
-;;      as staging-dir in coleslaw's config prior to enabling incremental builds
36
-;;   D) to further simplify *my* life, we assume the date of a piece of content
37
-;;      will never be changed retroactively, only its tags
22
+;; In contrast to the original incremental plans, full of shoving state into
23
+;; the right place by hand and avoiding writing pages to disk that hadn't
24
+;; changed, the new plan is to only avoid redundant parsing of content in
25
+;; the git repo. The rest of coleslaw's operation is "fast enough".
26
+;;
27
+;;   Prior to enabling the plugin a user must have a cl-store dump of the
28
+;;   database at ~/.coleslaw.db. We should provide a script to generate it.
38 29
 ;;
39 30
 ;; We're gonna be a bit dirty here and monkey patch. The compilation model
40 31
 ;; still isn't an "exposed" part of Coleslaw. After some experimentation maybe
41 32
 ;; we'll settle on an interface.
42 33
 
43
-(defvar *transients* '(coleslaw::numeric-index coleslaw::feed coleslaw::tag-feed)
44
-  "A list of document types that should be regenerated on any change to the blog.")
45
-
46 34
 (defun coleslaw::load-content ()
47 35
   (let ((db-file (rel-path (user-homedir-pathname) ".coleslaw.db")))
48 36
     (setf coleslaw::*site* (cl-store:restore db-file))
49 37
     (loop for (status path) in (get-updated-files)
50 38
        do (update-content status path))
51 39
     (coleslaw::update-content-metadata)
52
-    (dolist (doc-type *transients*)
53
-      (discover (find-class doc-type)))
40
+    (do-subclasses (itype index)
41
+      ;; Discover's before method will delete the possibly outdated indexes.
42
+      (discover itype))
54 43
     (cl-store:store coleslaw::*site* db-file)))
55 44
 
56 45
 (defun update-content (status path)
@@ -72,75 +61,18 @@
72 61
         (when-let (ctype (find extension ctypes :test #'class-name-p))
73 62
           (call-next-method status path :ctype ctype))))))
74 63
 
75
-;; TODO: If the last content from a given month or with a given tag
76
-;; is deleted, delete the index. Unfortunately, the tag/month links
77
-;; won't be updated on all indexes since we only regenerate them for new posts.
78
-
79 64
 (defmethod process-change ((status (eql :deleted)) path &key)
80
-  (let* ((old (find-content-by-path path))
81
-         (month-index (find-month-index (content-date old))))
82
-    (delete old (index-content month-index))
83
-    (dolist (tag (content-tags old))
84
-      (let ((tag-index (find-tag-index tag)))
85
-        (delete old (index-content tag-index))))
65
+  (let ((old (find-content-by-path path)))
86 66
     (delete-document old)))
87 67
 
88
-(defmethod process-change ((status (eql :modified)) path &key)
68
+(defmethod process-change ((status (eql :modified)) path &key ctype)
89 69
   (let ((old (find-content-by-path path))
90 70
         (new (construct ctype (read-content path))))
91 71
     (delete-document old)
92
-    ;; TODO:
93
-    ;; Iterate over tags in new, replacing old with new in each tag index's content.
94
-    ;; If there are new tags/date, add it to relevant indices (or create them).
95
-    ;; If tags/date are removed, remove from relevant indices (or delete them).
96
-    (add-document new)
97
-    (write-document new)))
72
+    (add-document new)))
98 73
 
99 74
 (defmethod process-change ((status (eql :added)) path &key ctype)
100
-  (let* ((new (construct ctype (read-content path)))
101
-         (tags (content-tags new))
102
-         (month (subseq (content-date new) 0 7)))
103
-    (maybe-add-month-index new month)
104
-    (dolist (tag tags)
105
-      (maybe-add-tag-index new tag))
106
-    (add-document new)
107
-    ;; FIXME: New posts won't have prev/next links populated.
108
-    (write-document new)))
109
-
110
-(defun coleslaw::compile-blog (staging)
111
-  "lulz. Do it live. DO IT ALL LIVE."
112
-  (dolist (doc-type *transients*)
113
-    (publish (find-class doc-type))))
114
-
115
-;; No-op. We'll be updating in place instead.
116
-(defmethod coleslaw:deploy (staging))
75
+  (let ((new (construct ctype (read-content path))))
76
+    (add-document new)))
117 77
 
118 78
 (defun enable ())
119
-
120
-;;;; Utils
121
-
122
-(defun delete-document (document)
123
-  "Given a DOCUMENT, delete it from the staging directory and in-memory DB."
124
-  (let ((url (page-url document)))
125
-    (delete-file (rel-path (staging-dir *config*) (namestring url)))
126
-    (remhash (page-url document) coleslaw::*site*)))
127
-
128
-(defun maybe-add-month-index (content month)
129
-  "Add a month index for MONTH containing CONTENT if one does not exist."
130
-(unless (find-month-index month)
131
-    (let ((month-index (coleslaw::index-by-month month (list content))))
132
-      (add-document month-index)
133
-      (write-document month-index))))
134
-
135
-(defun maybe-add-tag-index (content tag)
136
-  "Add a tag index for TAG containing CONTENT if one does not exist."
137
-  (unless (find-tag-index tag)
138
-    (let ((tag-index (coleslaw::index-by-tag tag (list content))))
139
-      (add-document tag-index)
140
-      (write-document tag-index))))
141
-
142
-(defun find-tag-index (tag)
143
-  (find (tag-slug tag) (find-all 'tag-index) :key #'index-slug :test #'equal))
144
-
145
-(defun find-month-index (date)
146
-  (find (subseq date 0 7) (find-all 'month-index) :key #'index-slug :test #'equal))