diff options
| -rw-r--r-- | src/redisload.clj | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/redisload.clj b/src/redisload.clj index 8796d9e..1ca7815 100644 --- a/src/redisload.clj +++ b/src/redisload.clj @@ -49,18 +49,22 @@ WHERE (def hall-map (ref {})) (def popular-map (ref {})) (def score-map (ref {})) +(def daily-hall-map (ref {})) (defn update-popular [r] (dosync - (let [author (:author r) - msg-id (:message_id r) - user-map (get @popular-map author {}) - msg-cnt (get user-map msg-id 0) - hall-cnt (get @hall-map msg-id 0) - usr-cnt (get @score-map author 0)] + (let [author (:author r) + msg-id (:message_id r) + msg-dt (format-yyyymmdd (:message_ts r)) + user-map (get @popular-map author {}) + msg-cnt (get user-map msg-id 0) + hall-cnt (get @hall-map msg-id 0) + usr-cnt (get @score-map author 0)] (alter score-map assoc author (inc usr-cnt)) (alter hall-map assoc msg-id (inc hall-cnt)) - (if (:is_image r) + (when (:is_image r) + (alter daily-hall-map + update-in [msg-dt msg-id] #(inc (or % 0))) (alter popular-map assoc author (assoc user-map msg-id (inc msg-cnt))))))) @@ -91,6 +95,15 @@ WHERE (redis/zadd redis-hall-key score msg-id))) (println "cached hall-of-fame"))) +(defn transmit-daily-hall [] + (doseq [[dt msgs] (sort-by first @daily-hall-map)] + (let [datekey (redis-daily-hall-key dt)] + (redis/atomically + (redis/del datekey) + (doseq [[msg-id score] (take 200 (sort-by #(- (second %)) msgs))] + (redis/zadd datekey score msg-id)) + (println "inserted daily hall into" datekey))))) + (println "streaming tags") (stream-tags [update-popular]) (println (format "processed %s tags" @tag-counter)) @@ -98,5 +111,6 @@ WHERE (redis/with-server redis-server (transmit-favscores) (transmit-popular) - (transmit-hall)) + (transmit-hall) + (transmit-daily-hall)) |
