--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/newseasons/models/keys.clj Thu Sep 29 23:19:31 2011 -0400
@@ -0,0 +1,13 @@
+(ns newseasons.models.keys)
+
+(defn key-show [id]
+ (str "shows:" id))
+
+(defn key-user [email]
+ (str "users:" email))
+
+(defn key-user-shows [email]
+ (str "users:" email ":shows"))
+
+(defn key-show-watchers [id]
+ (str "shows:" id ":watchers"))
--- a/src/newseasons/models/shows.clj Thu Sep 29 23:10:14 2011 -0400
+++ b/src/newseasons/models/shows.clj Thu Sep 29 23:19:31 2011 -0400
@@ -1,4 +1,5 @@
(ns newseasons.models.shows
+ (:use newseasons.models.keys)
(:use [aleph.redis :only (redis-client)]))
@@ -15,19 +16,16 @@
; }
; Code ------------------------------------------------------------------------
-(defn- show-key [id]
- (str "shows:" id))
-
(defn show-get [id]
- (apply hash-map @(r [:hgetall (show-key id)])))
+ (apply hash-map @(r [:hgetall (key-show id)])))
(defn show-set-title! [id new-title]
- @(r [:hset (show-key id) "title" new-title]))
+ @(r [:hset (key-show id) "title" new-title]))
(defn show-set-image! [id new-image]
- @(r [:hset (show-key id) "image" new-image]))
+ @(r [:hset (key-show id) "image" new-image]))
(defn show-set-url! [id new-url]
- @(r [:hset (show-key id) "url" new-url]))
+ @(r [:hset (key-show id) "url" new-url]))
--- a/src/newseasons/models/users.clj Thu Sep 29 23:10:14 2011 -0400
+++ b/src/newseasons/models/users.clj Thu Sep 29 23:19:31 2011 -0400
@@ -1,4 +1,5 @@
(ns newseasons.models.users
+ (:use newseasons.models.keys)
(:require [noir.util.crypt :as crypt])
(:use [aleph.redis :only (redis-client)]))
@@ -13,29 +14,29 @@
; email: the email address for ease of use
; pass: the user's hashed password
; }
-; user:<email address>:shows = #(show-id, ...)
+; user:<email address>:shows = #{show-id, ...}
+;
+; The show watching data is also denormalized based on show.
+;
+; shows:<id>:watchers - #{email, ...}
; Code ------------------------------------------------------------------------
-(defn- user-key [email]
- (str "users:" email))
-
-(defn- user-key-shows [email]
- (str "users:" email ":shows"))
-
(defn user-get [email]
- (let [user (apply hash-map @(r [:hgetall (user-key email)]))]
+ (let [user (apply hash-map @(r [:hgetall (key-user email)]))]
(when (not (empty? user))
(merge {:email (user "email") :pass (user "pass")}
- {:shows @(r [:smembers (user-key-shows email)])}))))
+ {:shows @(r [:smembers (key-user-shows email)])}))))
(defn user-set-email! [email new-email]
- @(r [:hset (user-key email) "email" new-email]))
+ @(r [:hset (key-user email) "email" new-email]))
(defn user-set-pass! [email new-pass]
- @(r [:hset (user-key email) "pass" (crypt/encrypt new-pass)]))
+ @(r [:hset (key-user email) "pass" (crypt/encrypt new-pass)]))
(defn user-add-show! [email show-id]
- @(r [:sadd (user-key-shows email) show-id]))
+ @(r [:sadd (key-user-shows email) show-id])
+ @(r [:sadd (key-show-watchers show-id) email]))
(defn user-rem-show! [email show-id]
- @(r [:srem (user-key-shows email) show-id]))
+ @(r [:srem (key-user-shows email) show-id])
+ @(r [:srem (key-show-watchers show-id) email]))