From 968faa6192e7c95a7b1cbfdd5d35fb7253b8984f Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Mon, 30 Aug 2010 22:52:44 -0400 Subject: Fixed directory queries and heart animations --- src/site.clj | 61 +++++++++++++++++++++++++++++++++------------------ src/utils.clj | 8 +++---- static/js/pichat.js | 46 ++++++++++++++++++++++---------------- template/directory.st | 24 +++++++------------- template/log.st | 14 +++++------- 5 files changed, 84 insertions(+), 69 deletions(-) diff --git a/src/site.clj b/src/site.clj index 297f4a5..cebf62e 100644 --- a/src/site.clj +++ b/src/site.clj @@ -592,38 +592,55 @@ order by count desc limit ? offset ?") "score_ent" (score-to-entity score) "score" score))) -(def recent-posts-query " -SELECT u.user_id, u.nick, u.avatar, - m.content, m.message_id -FROM users u, messages m -WHERE u.user_id = ANY(?) - AND m.message_id = +(defn recent-posts-query [user-id] + (format " +SELECT u.user_id, u.nick, u.avatar, + m.content, m.message_id%s +FROM users u +LEFT JOIN messages m on m.message_id = (SELECT message_id FROM messages WHERE user_id = u.user_id AND is_image AND room_id IN (SELECT room_id from rooms where admin_only = false) - ORDER BY created_on desc LIMIT 1); -") + ORDER BY created_on desc LIMIT 1) +WHERE u.user_id = ANY(?)" + (if user-id + (format + ", + EXISTS (SELECT 1 FROM tags + WHERE tag = 'favorite' AND user_id = %s AND message_id = m.message_id) AS favorited" + user-id) + ", false AS favorited"))) + +(defn lookup-recent-posts [user-tag-id user-ids] + (do-select [(recent-posts-query user-tag-id) + (sql-array "int" user-ids)])) + +(defn lookup-recent-posts-tagless [user-tag-id user-ids] + (do-select [(recent-posts-query nil) + (sql-array "int" user-ids)])) + +(def directory-cache-ttl (minutes 10)) +(def memoized-lookup-recent-posts-tagless + (ttl-memoize lookup-recent-posts-tagless directory-cache-ttl)) + -(defn add-recent-posts [users] +(defn add-recent-posts [user-id users] (if-not (empty? users) - (let [ids (map :user_id users) - res (do-select [recent-posts-query (sql-array "int" ids)])] + (let [f (if user-id lookup-recent-posts lookup-recent-posts-tagless) + res (f user-id (map :user_id users))] (for [u users] (merge u (find-first #(= (:user_id u) (:user_id %)) res)))))) -(defn get-directory-info [offset] +(defn get-directory-info [user-id offset] (map process-directory-entry - (add-recent-posts + (add-recent-posts user-id (get-user-ranking offset *per-directory-page*)))) - -(def directory-cache-ttl (minutes 10)) -(def memoized-get-directory-info - (ttl-memoize get-directory-info directory-cache-ttl)) (defn directory [session offset] (let [st (fetch-template "directory" session) - users (memoized-get-directory-info offset)] + users (get-directory-info (:user_id session) offset)] + (prn users) (.setAttribute st "users" users) (cond (= offset 0) (.setAttribute st "prev" false) (= offset 1) (.setAttribute st "prev" "") @@ -1360,6 +1377,8 @@ WHERE u.user_id = ANY(?) (start-user-flusher!) (start-session-pruner!) (start! hall-results) -(if (= *server-url* "http://dump.fm") - (do (start! feed-downloader) - (start! feed-inserter))) + +; Scott 2010/8/30: disable feeds to test impact on server load +;(if (= *server-url* "http://dump.fm") +; (do (start! feed-downloader) +; (start! feed-inserter))) diff --git a/src/utils.clj b/src/utils.clj index 7f56f61..dd5530a 100755 --- a/src/utils.clj +++ b/src/utils.clj @@ -58,10 +58,10 @@ (declare stringify-and-escape) (defn escape-html-deep [o] (if (map? o) - (stringify-and-escape o) - (if (seq? o) - (map escape-html-deep o) - (escape-html o)))) + (stringify-and-escape o) + (cond (seq? o) (map escape-html-deep o) + (or (true? o) (false? o)) o + :else (escape-html o)))) (defn stringify-and-escape [m] (zipmap (map str* (keys m)) (map escape-html-deep (vals m)))) diff --git a/static/js/pichat.js b/static/js/pichat.js index 9287cc1..13e0036 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -501,7 +501,7 @@ function initChat() { messageList = $("#messageList")[0] - initChatThumb() + initChatThumb(); scrollToEnd() scrollWatcher() @@ -583,14 +583,13 @@ function initLog() { var t = $(this); t.html(buildMsgContent(t.text())); }); - initLogThumb(); + initLogThumb(".logged-dump .thumb", '.dump'); } -// jesus this logic is ugly -function initLogThumb(){ - $(".logged-dump .thumb").bind('mouseover mouseout', +function initLogThumb(selector, parentSelector) { + $(selector).bind('mouseover mouseout', function(e) { - var favorited = $(this).parents(".dump").hasClass("favorite") ? true : false; + var favorited = $(this).parents(parentSelector).hasClass("favorite") ? true : false; if (e.type == "mouseover") { if (favorited) { $(this).attr("src", Imgs.logThumbOff); @@ -602,19 +601,29 @@ function initLogThumb(){ if (favorited) { $(this).attr("src", Imgs.logThumb); $(this).stop().animate(Anim.logThumb, 'fast'); - } else { + } else { $(this).attr("src", Imgs.logThumbOff); $(this).stop().animate(Anim.logThumb, 'fast'); } } }) -} + } -function initChatThumb(){ - - $(".chat-thumb").live('mouseover mouseout', +function initChatThumb() { + $(".chat-thumb").live('mouseover mouseout', function(e) { var favorited = $(this).parents(".dump").hasClass("favorite") ? true : false; + if (e.type == "mouseover") { + if (favorited) { + $(this).attr("src", Imgs.chatThumbOff); + } else { + $(this).attr("src", Imgs.chatThumbBig); + $(this).stop().animate(Anim.chatThumbBig, 'fast') + } + } else { // mouseout + if (favorited) { + $(this).attr("src", Imgs.chatThumb); + var favorited = $(this).parents(".dump").hasClass("favorite") ? true : false; if (e.type == "mouseover") { if (favorited) { $(this).attr("src", Imgs.chatThumbOff); @@ -626,17 +635,15 @@ function initChatThumb(){ if (favorited) { $(this).attr("src", Imgs.chatThumb); $(this).stop().animate(Anim.chatThumb, 'fast'); - } else { - $(this).stop().animate(Anim.chatThumbTiny, 'fast', 'swing', + } else { + $(this).stop().animate(Anim.chatThumbTiny, 'fast', 'swing', function(){ $(this).attr("src", Imgs.chatThumbDot) - $(this).animate(Anim.chatThumb, 0) + $(this).animate(Anim.chatThumb, 0) }) + }} } - } - }) -} - + }})} function paletteToChat(img){ var chatText = $("#msgInput").val() @@ -986,7 +993,8 @@ function initDirectory() { var t = $(this); t.html(buildMsgContent(t.text())); }); - Search.init() + Search.init() + initLogThumb('.dlogged-dump .thumb', '.dlogged-dump'); } //big hand stuff diff --git a/template/directory.st b/template/directory.st index 0611697..e3b3df0 100644 --- a/template/directory.st +++ b/template/directory.st @@ -9,33 +9,25 @@ - - $banner()$

-
-

Directory


Ordered by fav count
- - - -

- - -
+
+

Directory


+

Ordered by fav count


+

$if(users)$ - $users:{ dump | -
+ $users:{ dump | +
$endif$ @@ -53,7 +45,7 @@
last post
$dump.content$
- $share_buttons()$ + $share_buttons(dump=dump)$
}$ $else$ diff --git a/template/log.st b/template/log.st index 5a36611..92a0f75 100644 --- a/template/log.st +++ b/template/log.st @@ -9,15 +9,11 @@ $banner()$
- - -
- -
-

$roomkey$ log


-
- -
+
+
+

$roomkey$ log


+
+
$if(dumps)$ -- cgit v1.2.3-70-g09d2