diff options
| -rw-r--r-- | db/0-create.psql | 4 | ||||
| -rw-r--r-- | src/site.clj | 39 | ||||
| -rw-r--r-- | src/tags.clj | 6 | ||||
| -rw-r--r-- | static/js/pichat.js | 18 | ||||
| -rw-r--r-- | static/webcam/webcam.js | 2 |
5 files changed, 25 insertions, 44 deletions
diff --git a/db/0-create.psql b/db/0-create.psql index 2771676..3ab384c 100644 --- a/db/0-create.psql +++ b/db/0-create.psql @@ -12,7 +12,7 @@ CREATE TABLE users ( bio text NOT NULL DEFAULT '', profile_bg text ); -CREATE INDEX users_nick_idx ON users (lower(nick)); +CREATE INDEX users_nick_lowercase_idx ON users (lower(nick)); CREATE TABLE rooms ( room_id SERIAL PRIMARY KEY, @@ -66,7 +66,7 @@ CREATE TABLE tags ( CREATE INDEX tags_user_id_idx ON tags (user_id); CREATE INDEX tags_message_id_idx ON tags (message_id); CREATE INDEX tags_created_on_id_idx ON tags (created_on DESC); -CREATE INDEX tags_tag_idx ON tags (lower(tag)); +CREATE INDEX tags_tag_lowercase_idx ON tags (lower(tag)); INSERT INTO rooms (key, name, description, admin_only) VALUES ('dumpfm', 'Room A', 'Hangout', false); diff --git a/src/site.clj b/src/site.clj index bf745c9..1ecec31 100644 --- a/src/site.clj +++ b/src/site.clj @@ -266,43 +266,24 @@ ;; User-id/nick cache ;; I keep needing to grab user-id from a nick or nick from a user-id so I thought I'd cache them -(def user-id-nick-cache (ref {})) -(def *user-id-nick-cache-size* 500) +(def user-id-cache (ref {})) +(def *user-id-cache-size* 500) -;; this is really ugly, need to make this nicer or get rid of it -(defnk user-id-from-nick-or-nick-from-user-id [:nick false :user-id false] - (let [cache-key (or nick (str "~" user-id)) - found (@user-id-nick-cache cache-key)] +(defn user-id-from-nick [nick] + (let [nick (lower-case nick) + found (@user-id-cache nick)] (if found found - (let [query (if nick - (str "SELECT user_id FROM users WHERE lower(nick) = ?") - (str "SELECT nick FROM users WHERE user_id = ?")) - res (first (do-select [query (or nick user-id)]))] + (let [query (str "SELECT user_id FROM users WHERE lower(nick) = ?") + res (first (do-select [query nick]))] (if (nil? res) nil - (let [found (if nick - (res :user_id) - (res :nick)) - cache-key2 (if nick - (str "~" found) - (lower-case found))] + (let [found (res :user_id)] (dosync - (if (> (count @user-id-nick-cache) *user-id-nick-cache-size*) (ref-set user-id-nick-cache {})) - (alter user-id-nick-cache assoc cache-key found cache-key2 (or nick user-id)) - ) + (if (> (count @user-id-cache) *user-id-cache-size*) (ref-set user-id-cache {})) + (alter user-id-cache assoc nick found)) found)))))) -(defn user-id-from-nick [nick] (user-id-from-nick-or-nick-from-user-id :nick (lower-case nick))) -(defn nick-from-user-id [user-id] (user-id-from-nick-or-nick-from-user-id :user-id user-id)) - -;; Favorites cache - -(def favorites-cache (ref [])) -(def *favorites-cache-size* 50) - - - ;; Login code (defn is-vip? [session] diff --git a/src/tags.clj b/src/tags.clj index 77933d6..3878a18 100644 --- a/src/tags.clj +++ b/src/tags.clj @@ -7,7 +7,7 @@ compojure utils)) -; save all spaces in tags as dashes +; save all spaces in tags as dashes? (defn normalize-tag-for-db [tag] (str tag)) ; (.replace tag " " "-")) ; todo: remove unicode escape sequences and line breaks and stuff? @@ -23,7 +23,6 @@ (assoc row :tags_json (json-str (row :tags)))) ; turn "a 1 b 2" to ({:nick a :tag 1}, {:nick b :tag 2}) -; this seems to be a waste of cpu and memory, but i'm trying to make these easily accessible from templates ; also: i can't figure out how to access array indexes directly in StringTemplate templates ;; (defn parse-tags-from-row [row] ;; (assoc row :tags @@ -40,7 +39,7 @@ (assoc tags tag [nick])))) ; making something like {"tag1": ["nick a", "nick b"], "tag2": ["nick c", "nick d"]} -; why is building data structures in clojure so hard for me +; from the db data which looks like "nicka:tag1 nickb:tag1 nickc:tag2 nickd:tag2" (defn parse-tags-from-row-as-tag-map [row] (if (row :tags) (assoc row :tags @@ -66,7 +65,6 @@ ;; so, a subquery could be used when offset is large ;; one other thing we could do is include message_id in 'next page' url (tumblr & reddit do that for example) ;; but probably people don't page back too far anyway -;; (not used yet) (defn fetch-dumps-by-room-query-faster [image-only] (str " SELECT m.content, m.message_id, m.created_on, diff --git a/static/js/pichat.js b/static/js/pichat.js index bdd2471..111f574 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -22,22 +22,20 @@ isEmptyObject = function(obj) { } -function isCSSPropertySupported(prop){ - return prop in document.body.style; -} +function isCSSPropertySupported(prop){ return prop in document.body.style } function escapeHtml(txt) { if (!txt) { return ""; } else { return $("<span>").text(txt).html(); } } - URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i; function getImagesAsArray(text) { var imgs = [] var urls = text.match(URLRegex) + if (urls === null) return imgs for (var i = 0; i<urls.length; i++){ var url = urls[i] var urlWithoutParams = url.replace(/\?.*$/i, ""); @@ -319,9 +317,11 @@ function refresh() { } function initChat() { - $('.msgDiv .content').each(function() { - var t = $(this); - t.html(buildMsgContent(t.text())); + $('.oldmsg').each(function() { + var dump = $(this); + var content = dump.find(".content") + MessageContentCache[dump.attr("id").substr(8)] = content.text() + content.html(buildMsgContent(content.text())); }); $('#msgInput').keyup(ifEnter(submitMessage)); @@ -809,7 +809,9 @@ Tag = { } else { Tag.add(message.id, "favorite") $(button).parents(".dump").addClass("favorite") - if (RawFavs && MessageContentCache[message.id]) { + if (RawFavs && MessageContentCache[message.id]) { // chat ui stuff + if ($("#palette-button").css("display") == "none") + paletteButtonShowAnim() RawFavs[message.id] = MessageContentCache[message.id] paletteImageCache = false } diff --git a/static/webcam/webcam.js b/static/webcam/webcam.js index f2e287b..aa7bf0a 100644 --- a/static/webcam/webcam.js +++ b/static/webcam/webcam.js @@ -57,7 +57,7 @@ window.webcam = { $("#webcam-button-upload").addClass("invisible") $("#webcam-button-snap").removeClass("invisible") $("#effects-msg").removeClass("invisible").fadeOut(70000) - + paletteHide() blinkStart() }, |
