summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Ostler <scottbot9000@gmail.com>2010-06-23 15:57:14 -0400
committerScott Ostler <scottbot9000@gmail.com>2010-06-23 15:57:14 -0400
commit15f5a8ed8e981486697790fe9613b1c26dceda42 (patch)
tree172b66b346bb4d8d90ec255125a02576b182280d /src
parentc4041b4766f8afa0c462fbea2963b61bc43f0e08 (diff)
Added faving to hall of fame
Diffstat (limited to 'src')
-rw-r--r--src/fame.clj2
-rw-r--r--src/site.clj7
-rw-r--r--src/tags.clj20
3 files changed, 26 insertions, 3 deletions
diff --git a/src/fame.clj b/src/fame.clj
index 8f0ae4f..cd28e05 100644
--- a/src/fame.clj
+++ b/src/fame.clj
@@ -3,7 +3,7 @@
utils))
; should probably cache this to disk somewhere
-(def hall-of-fame-update-frequency (* 4 60 60))
+(def hall-of-fame-update-frequency (* 3 60 60))
(def hall-of-fame-query "
select m.created_on, m.message_id, m.content, u.nick, u.avatar, r.key, count(*)
diff --git a/src/site.clj b/src/site.clj
index 6a011c6..0967431 100644
--- a/src/site.clj
+++ b/src/site.clj
@@ -1047,8 +1047,11 @@ FROM users u
(unknown-page)))
(defn hall-of-fame [session]
- (let [st (fetch-template "fame" session)]
- (.setAttribute st "dumps" (map process-message-for-output (poll hall-results)))
+ (let [st (fetch-template "fame" session)
+ msgs (add-user-favs-to-msgs (poll hall-results)
+ (session :user_id))]
+ (println "hall msgs:" msgs)
+ (.setAttribute st "dumps" (map process-message-for-output msgs))
(.toString st)))
;; Compojure Routes
diff --git a/src/tags.clj b/src/tags.clj
index 4d1dda0..de0b476 100644
--- a/src/tags.clj
+++ b/src/tags.clj
@@ -63,6 +63,26 @@
(assoc row :favorited true)
row))
+(def user-fav-query "
+SELECT v
+FROM UNNEST(?) as v
+WHERE EXISTS
+ (SELECT 1 FROM tags
+ WHERE user_id = ?
+ AND message_id = v
+ AND tag = 'favorite')
+")
+
+(defn add-user-favs-to-msgs [msgs user-id]
+ (let [faved-ids (set
+ (map :v
+ (do-select [user-fav-query
+ (sql-array "int" (map :message_id msgs))
+ user-id])))]
+ (for [m msgs]
+ (if (contains? faved-ids (:message_id m))
+ (assoc m :favorited true)
+ m))))
(defn explain-query [query] (str "EXPLAIN ANALYZE " query))