[Cache (TOTAL-ITEMS QUERY-VIEW) ephemerally clinton@unknownlamer.org**20090301233004 Ignore-this: c69f4af3150d1bd4e8b6f5a6c369e67d With Elephant at least counting is pretty slow (scans the entire btree) and so this helps a bit it seems. ] { hunk ./src/query-view.lisp 32 - cached instances. For internal use only."))) +cached instances. For internal use only.") + (%count :initform nil :documentation "ephemeral cache of item +count. For internal use only."))) hunk ./src/query-view.lisp 67 -(defmethod current-items ((view query-view)) - ;; This uses an ephemeral cache that survives only for the +(labels ((cache-valid-p (view %cache-slot) + (let ((%cache (slot-value view %cache-slot))) + (and %cache (eq (car %cache) (context.request *context*))))) + (update-cache (view %cache-slot new-value) + (setf (slot-value view %cache-slot) + (cons (context.request *context*) new-value)))) + ;; These use an ephemeral cache that survives only for the hunk ./src/query-view.lisp 77 - (labels ((cache-valid-p (view) - (with-slots (%cache) view - (and %cache (eq (car %cache) (context.request *context*))))) - (update-cache (view) - (with-slots (%cache) view - (setf %cache - (cons (context.request *context*) + (defmethod current-items ((view query-view)) + (if (cache-valid-p view '%cache) + (cdr (slot-value view '%cache)) + (cdr (update-cache view '%cache hunk ./src/query-view.lisp 84 - :from-end (reversep view))))))) - (if (cache-valid-p view) - (cdr (slot-value view '%cache)) - (cdr (update-cache view))))) + :from-end (reversep view)))))) + + (defmethod total-items :around ((view query-view)) + (if (cache-valid-p view '%count) + (cdr (slot-value view '%count)) + (cdr (update-cache view '%count (call-next-method)))))) }