[Add comment count pseudoindex to weblog entries clinton@unknownlamer.org**20090505193951 Ignore-this: 6d12ba1a3782f5b1f3fa8ecc3f800a6b ] addfile ./misc/upgrade-3_comment-count.lisp hunk ./misc/upgrade-3_comment-count.lisp 1 - +(defun initialize-comment-counts () + (mapc (lambda (entry) + (setf (slot-value entry 'beesknees.weblog::%comment-count) + 0)) + (elephant:get-instances-by-class 'beesknees.weblog:weblog-entry)) + (mapc + (lambda (comment) + (when (beesknees.weblog:comment-parent comment) + (elephant:ensure-transaction () + (iter:iter (iter:for p :initially (beesknees.weblog:comment-parent comment) + :then (beesknees.weblog:comment-parent p)) + (iter:finding p :such-that (typep p 'beesknees.weblog:weblog-entry)) + (iter:finally (setf (slot-value p 'beesknees.weblog::%comment-count) + (1+ (slot-value p 'beesknees.weblog::%comment-count)))))))) + (elephant:get-instances-by-class 'beesknees.weblog:weblog-comment))) hunk ./src/packages.lisp 10 + #:entry-comment-count hunk ./src/weblog.lisp 7 - (body :initarg :body :accessor entry-body))) + (body :initarg :body :accessor entry-body) + (%comment-count :initform 0 :reader entry-comment-count))) hunk ./src/weblog.lisp 17 +(defmethod initialize-instance :after ((comment weblog-comment) + &key (from-oid nil from-oid-p) parent + &allow-other-keys) + (declare (ignore from-oid)) + (unless (or from-oid-p (not parent)) + (ensure-transaction () + (iter:iter (iter:for p :initially (comment-parent comment) + :then (comment-parent p)) + (iter:finding p :such-that (typep p 'weblog-entry)) + (iter:finally (setf (slot-value p '%comment-count) + (1+ (slot-value p '%comment-count)))))))) + +(defmethod elephant:drop-instance :before ((comment weblog-comment)) + (when (comment-parent comment) + (ensure-transaction () + (iter:iter (iter:for p :initially (comment-parent comment) + :then (comment-parent p)) + (iter:finding p :such-that (typep p 'weblog-entry)) + (iter:finally (setf (slot-value p '%comment-count) + (1- (slot-value p '%comment-count)))))))) + hunk ./tal/bee-blog-list-entry.tal 1 + hunk ./tal/bee-blog-list-entry.tal 16 - >view full comment + >comments () comment