Skip to content

Commit

Permalink
Stop journalling events that don't change the state
Browse files Browse the repository at this point in the history
  • Loading branch information
klauswuestefeld committed Dec 9, 2023
1 parent 74e9bfa commit e699bbd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/prevayler_clj_aws/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@
Prevayler
(handle! [this event]
(locking this ; (I)solation: strict serializability.
(let [timestamp (timestamp-fn)
(let [current-state @state-atom
timestamp (timestamp-fn)
new-state (business-fn @state-atom event timestamp)] ; (C)onsistency: must be guaranteed by the handler. The event won't be journalled when the handler throws an exception.)
(write-event! dynamodb-client dynamodb-table new-partkey
(swap! order-atom inc)
[timestamp event (hash new-state)]) ; (D)urability
(reset! state-atom new-state)))) ; (A)tomicity
(when-not (identical? new-state current-state)
(write-event! dynamodb-client dynamodb-table new-partkey
(swap! order-atom inc)
[timestamp event (hash new-state)]) ; (D)urability
(reset! state-atom new-state))))) ; (A)tomicity
(timestamp [_] (timestamp-fn))

IDeref (deref [_] @state-atom)
Expand Down

0 comments on commit e699bbd

Please sign in to comment.