2014-05-16 14:45:17 -04:00
|
|
|
(eval-when (:compile-toplevel :load-toplevel)
|
|
|
|
(ql:quickload 'cl-store))
|
|
|
|
|
|
|
|
(defpackage :coleslaw-incremental
|
|
|
|
(:use :cl)
|
2014-05-18 23:59:27 -04:00
|
|
|
(:import-from :alexandria #:when-let)
|
2014-06-03 17:18:24 -04:00
|
|
|
(:import-from :coleslaw #:*config*
|
|
|
|
#:content
|
|
|
|
#:index
|
2014-06-03 11:15:02 -04:00
|
|
|
#:discover
|
2014-05-18 23:59:27 -04:00
|
|
|
#:get-updated-files
|
2014-05-16 14:45:17 -04:00
|
|
|
#:find-content-by-path
|
2014-06-03 11:15:02 -04:00
|
|
|
#:add-document
|
2014-06-03 16:37:56 -04:00
|
|
|
#:delete-document
|
2014-06-03 11:15:02 -04:00
|
|
|
;; Private
|
|
|
|
#:all-subclasses
|
2014-06-03 16:37:56 -04:00
|
|
|
#:do-subclasses
|
2014-06-03 17:18:24 -04:00
|
|
|
#:read-content
|
2014-06-03 11:15:02 -04:00
|
|
|
#:construct
|
2014-06-03 16:41:12 -04:00
|
|
|
#:rel-path
|
2014-06-03 17:18:24 -04:00
|
|
|
#:repo
|
2014-06-03 16:41:12 -04:00
|
|
|
#:update-content-metadata)
|
2014-05-16 14:45:17 -04:00
|
|
|
(:export #:enable))
|
|
|
|
|
|
|
|
(in-package :coleslaw-incremental)
|
|
|
|
|
2014-06-03 16:37:56 -04:00
|
|
|
;; In contrast to the original incremental plans, full of shoving state into
|
|
|
|
;; the right place by hand and avoiding writing pages to disk that hadn't
|
|
|
|
;; changed, the new plan is to only avoid redundant parsing of content in
|
|
|
|
;; the git repo. The rest of coleslaw's operation is "fast enough".
|
|
|
|
;;
|
|
|
|
;; Prior to enabling the plugin a user must have a cl-store dump of the
|
2014-06-03 18:13:12 -04:00
|
|
|
;; database at ~/.coleslaw.db. There is a dump_db shell script in
|
|
|
|
;; examples to generate the database dump.
|
2014-06-03 14:51:24 -04:00
|
|
|
;;
|
|
|
|
;; We're gonna be a bit dirty here and monkey patch. The compilation model
|
2014-05-16 14:45:17 -04:00
|
|
|
;; still isn't an "exposed" part of Coleslaw. After some experimentation maybe
|
|
|
|
;; we'll settle on an interface.
|
|
|
|
|
|
|
|
(defun coleslaw::load-content ()
|
|
|
|
(let ((db-file (rel-path (user-homedir-pathname) ".coleslaw.db")))
|
|
|
|
(setf coleslaw::*site* (cl-store:restore db-file))
|
|
|
|
(loop for (status path) in (get-updated-files)
|
2014-11-02 23:04:45 -05:00
|
|
|
for file-path = (rel-path (repo-dir *config*) path)
|
2014-06-03 17:18:24 -04:00
|
|
|
do (update-content status file-path))
|
2014-06-03 16:41:12 -04:00
|
|
|
(update-content-metadata)
|
2014-06-03 18:13:12 -04:00
|
|
|
;; Discover's :before method will delete any possibly outdated indexes.
|
2014-06-03 16:37:56 -04:00
|
|
|
(do-subclasses (itype index)
|
|
|
|
(discover itype))
|
2014-05-16 14:45:17 -04:00
|
|
|
(cl-store:store coleslaw::*site* db-file)))
|
|
|
|
|
|
|
|
(defun update-content (status path)
|
|
|
|
(cond ((string= "D" status) (process-change :deleted path))
|
|
|
|
((string= "M" status) (process-change :modified path))
|
|
|
|
((string= "A" status) (process-change :added path))))
|
|
|
|
|
2014-05-18 23:59:27 -04:00
|
|
|
(defgeneric process-change (status path &key &allow-other-keys)
|
|
|
|
(:documentation "Updates the database as needed for the STATUS change to PATH.")
|
|
|
|
(:method :around (status path &key)
|
|
|
|
(let ((extension (pathname-type path))
|
|
|
|
(ctypes (all-subclasses (find-class 'content))))
|
|
|
|
;; This feels way too clever. I wish I could think of a better option.
|
|
|
|
(flet ((class-name-p (x class)
|
|
|
|
(string-equal x (symbol-name (class-name class)))))
|
2014-05-19 12:00:54 -04:00
|
|
|
;; If the updated file's extension doesn't match one of our content types,
|
|
|
|
;; we don't need to mess with it at all. Otherwise, since the class is
|
|
|
|
;; annoyingly tricky to determine, pass it along.
|
2014-05-18 23:59:27 -04:00
|
|
|
(when-let (ctype (find extension ctypes :test #'class-name-p))
|
|
|
|
(call-next-method status path :ctype ctype))))))
|
|
|
|
|
|
|
|
(defmethod process-change ((status (eql :deleted)) path &key)
|
2014-06-03 16:37:56 -04:00
|
|
|
(let ((old (find-content-by-path path)))
|
2014-05-19 12:00:54 -04:00
|
|
|
(delete-document old)))
|
2014-05-18 23:59:27 -04:00
|
|
|
|
2014-06-03 16:37:56 -04:00
|
|
|
(defmethod process-change ((status (eql :modified)) path &key ctype)
|
2014-05-19 12:00:54 -04:00
|
|
|
(let ((old (find-content-by-path path))
|
|
|
|
(new (construct ctype (read-content path))))
|
2014-06-03 14:51:24 -04:00
|
|
|
(delete-document old)
|
2014-06-03 16:37:56 -04:00
|
|
|
(add-document new)))
|
2014-05-18 23:59:27 -04:00
|
|
|
|
|
|
|
(defmethod process-change ((status (eql :added)) path &key ctype)
|
2014-06-03 16:37:56 -04:00
|
|
|
(let ((new (construct ctype (read-content path))))
|
|
|
|
(add-document new)))
|
2014-05-16 14:45:17 -04:00
|
|
|
|
|
|
|
(defun enable ())
|