diff options
| -rwxr-xr-x | src/site.clj | 17 | ||||
| -rwxr-xr-x | src/utils.clj | 11 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/site.clj b/src/site.clj index fe78633..a57cf16 100755 --- a/src/site.clj +++ b/src/site.clj @@ -21,8 +21,8 @@ feed)) (def *run-flusher* true) -(def *flusher-sleep-ms* 4000) -(def *user-timeout-ms* 15000) +(def *flusher-sleep* (seconds 4)) +(def *user-timeout* (seconds 15)) (def template-group (new StringTemplateGroup "dumpfm" "template")) (.setRefreshInterval template-group 3) @@ -42,10 +42,10 @@ (dosync (let [users (room :users) now (System/currentTimeMillis) - alive? (fn [[n u]] (> (u :last-seen) (- now *user-timeout-ms*)))] + alive? (fn [[n u]] (> (u :last-seen) (- now *user-timeout*)))] (ref-set users (into {} (filter alive? @users)))))) - (Thread/sleep *flusher-sleep-ms*) + (Thread/sleep *flusher-sleep*) (when *run-flusher* (send *agent* #'flush-inactive-users!)) x) @@ -392,7 +392,7 @@ (def *directory-listing* (ref [])) (def *per-directory-page* 25) (def *run-update-directory* true) -(def *update-directory-sleep-ms* (* 60 60 1000)) +(def *update-directory-sleep* (minutes 15)) (defn directory-search [offset] (let [directory @*directory-listing* @@ -407,14 +407,15 @@ "AND m.user_id = u.user_id " "AND m.created_on = (select max(created_on) from messages " " where user_id = u.user_id)")] - (when (> (count user-ids) 0) + (if (> (count user-ids) 0) (let [res (do-select [qry]) keys (map :user_id res) dict (zipmap keys res)] (map (fn [u] (let [u-id (u :user_id)] (stringify-and-escape (merge u (dict u-id))))) - users))))) + users)) + []))) (defn update-directory! [] (let [qry (str "SELECT u.user_id, COUNT(m) as cnt " @@ -428,7 +429,7 @@ (defn update-directory-agent-func [x] (update-directory!) - (Thread/sleep *update-directory-sleep-ms*) + (Thread/sleep *update-directory-sleep*) (when *run-update-directory* (send *directory-agent* #'update-directory-agent-func)) x) diff --git a/src/utils.clj b/src/utils.clj index 7abed4f..9a95430 100755 --- a/src/utils.clj +++ b/src/utils.clj @@ -14,11 +14,14 @@ :password "root"})) -(defn kbytes [b] - (* b 1024)) +;; Misc -(defn mbytes [b] - (* b 1024 1024)) +(defn seconds [t] (* t 1000)) +(defn minutes [t] (* t 60 1000)) + +(defn kbytes [b] (* b 1024)) + +(defn mbytes [b] (* b 1024 1024)) ;; JSON responses |
