summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.clj7
-rw-r--r--src/redisload.clj67
-rw-r--r--src/site.clj2
-rwxr-xr-xsrc/utils.clj5
4 files changed, 68 insertions, 13 deletions
diff --git a/src/config.clj b/src/config.clj
index c4e2fe3..1cf5ae6 100644
--- a/src/config.clj
+++ b/src/config.clj
@@ -15,6 +15,11 @@
".dump.fm"
""))
+(def db-server
+ (if (= *server-user* "dumpfmprod")
+ "192.168.162.138"
+ "localhost"))
+
(def redis-server
(if (= *server-user* "dumpfmprod")
{:host "192.168.156.111" :port 6379 :db 0 }
@@ -32,4 +37,4 @@
(def *vip-dumps-per-page* 200)
(def message-count-limit 200)
(def num-hall-dumps 50)
-(def max-content-size 2468) \ No newline at end of file
+(def max-content-size 2468)
diff --git a/src/redisload.clj b/src/redisload.clj
index 1ca7815..26888e3 100644
--- a/src/redisload.clj
+++ b/src/redisload.clj
@@ -1,4 +1,5 @@
(ns redisload
+ (:import java.util.Calendar)
(:use clojure.contrib.sql
clojure.contrib.str-utils
config
@@ -104,13 +105,63 @@ WHERE
(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))
-(redis/with-server redis-server
- (transmit-favscores)
- (transmit-popular)
- (transmit-hall)
- (transmit-daily-hall))
+(defn date-to-sql [dt]
+ (java.sql.Date. (.getTime dt)))
+(defn date-to-cal [dt]
+ (let [cal (Calendar/getInstance)]
+ (.setTime cal dt)
+ cal))
+
+(defn cal-to-date [cal]
+ (.getTime cal))
+
+(defn next-cal [cal]
+ (let [ret (.clone cal)]
+ (.add ret Calendar/DAY_OF_MONTH 1)
+ ret))
+
+(defn get-fav-date-range []
+ (let [{min :min max :max}
+ (first
+ (do-select ["select min(created_on)::date, max(created_on)::date from tags"]))
+ min (date-to-cal min)
+ max (date-to-cal max)]
+ (loop [acc [(cal-to-date min)]
+ cur min]
+ (let [next (next-cal cur)]
+ (if (.after cur max)
+ acc
+ (recur (conj acc (cal-to-date next)) next))))))
+
+
+(defn get-top-posts [dt limit]
+ (do-select ["
+ SELECT m.message_id as message_id, count(*) as score
+ FROM messages m, tags t, rooms r
+ WHERE m.message_id = t.message_id and m.room_id = r.room_id
+ AND m.user_id != t.user_id
+ AND m.created_on::date = ?::date
+ AND m.is_image
+ AND r.admin_only = false
+ GROUP BY m.message_id
+ ORDER BY score DESC
+ LIMIT ?" (date-to-sql dt) limit]))
+
+(defn build-daily-hall [dt]
+ (let [top-posts (get-top-posts dt 20)
+ datekey (redis-daily-hall-key (format-yyyymmdd dt))]
+ (println (count top-posts) "posts for" datekey)
+ (redis/with-server redis-server
+ (redis/atomically
+ (redis/del datekey)
+ (doseq [m top-posts]
+ (println (:message_id m) (:score m))
+ (redis/zadd datekey (:score m) (:message_id m)))))))
+
+(defn build-all-daily-hall []
+ (doseq [dt (get-fav-date-range)]
+ (build-daily-hall dt)))
+
+(build-daily-hall (parse-yyyy-mm-dd-date "2010-05-03")) \ No newline at end of file
diff --git a/src/site.clj b/src/site.clj
index 73d481d..fdcf089 100644
--- a/src/site.clj
+++ b/src/site.clj
@@ -194,7 +194,7 @@
(defn front-page [session]
(let [st (fetch-template "frontpage" session)
- date-str (format-yyyymmdd (Date.))
+ date-str "20100503";(format-yyyymmdd (Date.))
dumps (map process-message-for-output
(fetch-redis-daily-hall date-str 0 30))]
(.setAttribute st "dumps" dumps)
diff --git a/src/utils.clj b/src/utils.clj
index 84f185a..eb89cf1 100755
--- a/src/utils.clj
+++ b/src/utils.clj
@@ -23,12 +23,11 @@
compojure
config))
-(let [db-host "localhost"
- db-name "dumpfm"
+(let [db-name "dumpfm"
db-user "postgres"
db-pass "root"]
(def *db* {:datasource (doto (new PGPoolingDataSource)
- (.setServerName db-host)
+ (.setServerName db-server)
(.setDatabaseName db-name)
(.setUser db-user)
(.setPassword db-pass)