summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/site.clj39
-rw-r--r--src/tags.clj6
2 files changed, 12 insertions, 33 deletions
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,