Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn- log-insertion-counts
[rf]
(fn
([] (rf))
([session] (rf session))
([session batch]
(let [before-session session
after-session (rf session batch)]
(send-off logging-agent
(fn [_]
(let [before (into {} (map (fn [[k v]] [(:name k) (count v)])) (:insertions (inspect before-session)))
after (into {} (map (fn [[k v]] [(:name k) (count v)])) (:insertions (inspect after-session)))
delta (reduce-kv (fn [m k v]
(assoc m k (- (get after k 0) (get before k 0))))
{}
after)]
(log/info "session-from-db: insertion counts:"
(with-out-str
(clojure.pprint/print-table
(->> delta
(map (fn [[k v]]
(let [k (-> k str read-string name)]
{:rule k, :count v})))
(remove (comp zero? :count))
(sort-by (juxt :count :rule))
reverse)))))))
after-session))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.