Use ns as part of flood control message disambiguator

This commit is contained in:
Peter Taoussanis 2013-02-05 23:35:14 +07:00
parent de5ab76955
commit 6c359427d9
1 changed files with 5 additions and 4 deletions

View File

@ -140,19 +140,20 @@
((fn [apfn]
(if-not max-message-per-msecs
apfn
(let [;; {:msg last-appended-time-msecs ...}
(let [;; {:hash last-appended-time-msecs ...}
flood-timers (atom {})]
(fn [{:keys [message] :as apfn-args}]
(fn [{:keys [ns message] :as apfn-args}]
(let [now (System/currentTimeMillis)
hash (str ns "/" message)
allow? (fn [last-msecs]
(if last-msecs
(> (- now last-msecs) max-message-per-msecs)
true))]
(when (allow? (@flood-timers message))
(when (allow? (@flood-timers hash))
(apfn apfn-args)
(swap! flood-timers assoc message now))
(swap! flood-timers assoc hash now))
;; Occassionally garbage-collect all expired timers. Note
;; that due to snapshotting, garbage-collection can cause