summaryrefslogtreecommitdiff
path: root/src/site.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/site.clj')
-rw-r--r--src/site.clj39
1 files changed, 10 insertions, 29 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]