Skip to content

Commit

Permalink
trying to get recency mixin to work re ADWolf:#1207
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbysmith007 committed Jan 28, 2014
1 parent 8d28fcb commit 79c0436
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions recency.lisp
Expand Up @@ -37,12 +37,35 @@
((instance :accessor instance :initarg :instance :initform nil)
(history-info :accessor history-info :initarg :history-info :initform nil)))

(defmethod clsql-sys::update-records-from-instance :before ((o recency-mixin) &key database &allow-other-keys)
(declare (ignore database))
(defun %before-update-recency-check (o)
(let* ((history-info (get-history-info o))
(most-recent-historic-date
(convert-to-clsql-datetime
(first (alexandria:ensure-list history-info)))))
(when (and most-recent-historic-date
(when (and most-recent-historic-date (%retrieved-at o)
(clsql-sys::time< (%retrieved-at o) most-recent-historic-date))
(error 'recency-error :instance o :history-info history-info))))

(defun %after-update-recency-check (o)
(setf (%retrieved-at o)
(convert-to-clsql-datetime
(first (clsql:query "SELECT CURRENT_TIMESTAMP" :flatp t)))))

(defmethod clsql-sys::update-records-from-instance :before ((o recency-mixin) &key database &allow-other-keys)
(declare (ignore database))
(%before-update-recency-check o))

(defmethod clsql-sys::update-records-from-instance :after ((o recency-mixin) &key database &allow-other-keys)
(declare (ignore database))
(%after-update-recency-check o))

(defmethod clsql-sys::update-record-from-slots :before ((o recency-mixin) slots &key database &allow-other-keys)
(declare (ignore database slots))
(%before-update-recency-check o))

(defmethod clsql-sys::update-record-from-slots :after ((o recency-mixin) slots &key database &allow-other-keys)
(declare (ignore database slots))
(%after-update-recency-check o))



0 comments on commit 79c0436

Please sign in to comment.