summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Ostler <sbsotler@gmail.com>2010-11-23 01:23:57 -0500
committerScott Ostler <sbsotler@gmail.com>2010-11-23 01:23:57 -0500
commit2b7162504314d4207df4c462d3cad12ad144b7c0 (patch)
tree28deef1b0acd835e1537bd44ff47665158bc4ba9 /src
parent8c43debe825b0992322b2a6f2a77a6ce62d33af4 (diff)
Add directory/hall to redis loader
Diffstat (limited to 'src')
-rw-r--r--src/redisload.clj45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/redisload.clj b/src/redisload.clj
index 0e34e2c..07c1275 100644
--- a/src/redisload.clj
+++ b/src/redisload.clj
@@ -1,5 +1,6 @@
(ns redisload
(:use clojure.contrib.sql
+ clojure.contrib.str-utils
config
datalayer
utils)
@@ -26,7 +27,8 @@ WHERE
u.user_id = m.user_id AND
m.message_id = t.message_id AND
r.room_id = m.room_id AND
- u2.user_id = t.user_id
+ u2.user_id = t.user_id AND
+ r.admin_only = false
")
(def tag-counter (ref 0))
@@ -35,21 +37,30 @@ WHERE
(with-connection *db*
(with-query-results rs [tag-query]
(doseq [r rs]
+ (if (:admin_only r)
+ (println r))
(dosync
(ref-set tag-counter (inc @tag-counter)))
(doseq [f fs]
(f r))))))
-
+(def hall-map (ref {}))
(def popular-map (ref {}))
+(def score-map (ref {}))
(defn update-popular [r]
(if (and (:is_image r) (not (:admin_only r)))
(dosync
- (let [user-map (or (get @popular-map (:author r)) {})
- msg-cnt (or (get user-map (:message_id r)) 0)]
- (alter popular-map assoc (:author r)
- (assoc user-map (:message_id r) (inc msg-cnt)))))))
+ (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)]
+ (alter hall-map assoc msg-id (inc hall-cnt))
+ (alter score-map assoc author (inc usr-cnt))
+ (alter popular-map assoc author
+ (assoc user-map msg-id (inc msg-cnt)))))))
(defn transmit-popular []
(doseq [[nick msgs] @popular-map]
@@ -60,14 +71,30 @@ WHERE
(doseq [[msg-id score] (take (* num-popular-dumps 2)
sorted-msgs)]
(redis/zadd userkey score msg-id)))))
- ;; (redis/expire userkey (redis-days 2))))) -- TODO: schedule auto loader
(println "cached popular data for" (count @popular-map) "users"))
+(defn transmit-favscores []
+ (redis/atomically
+ (redis/del "favscores")
+ (doseq [[nick score] @score-map]
+ (redis/zadd "favscores" score (lower-case nick))))
+ (println "cached favscores for " (count @score-map) "users"))
+
+(defn transmit-hall []
+ (let [scores (take (* 2 num-hall-dumps)
+ (sort #(>= (second %1) (second %2)) @hall-map))]
+ (redis/atomically
+ (redis/del "hall")
+ (doseq [[msg-id score] scores]
+ (redis/zadd "hall" score msg-id)))))
+
+
(println "streaming tags")
(stream-tags [update-popular])
(println (format "processed %s tags" @tag-counter))
-
(redis/with-server redis-server
- (transmit-popular))
+ (transmit-favscores)
+ (transmit-popular)
+ (transmit-hall))