bugfix: ui caching disabled short urls

This commit is contained in:
Christian Mueller
2014-03-31 09:52:15 +02:00
parent 47b66d1e21
commit 1ba3b408d5
4 changed files with 15 additions and 10 deletions
+9 -7
View File
@@ -74,15 +74,16 @@
(GET "/:year/:month/:day/:title" [year month day title :as params]
(let [params (assoc (:query-params params)
:year year :month month :day day :title title)
note-id (api/build-key year month day title)]
note-id (api/build-key year month day title)
short-url (storage/create-short-url note-id params)]
(when (storage/note-exists? note-id)
(if (cache/has? @C note-id)
(if (cache/has? @C short-url)
(do
(swap! C cache/hit note-id)
(swap! C cache/hit short-url)
(storage/increment-note-view note-id))
(swap! C cache/miss note-id
(note-page note-id (storage/create-short-url note-id params))))
(cache/lookup @C note-id))))
(swap! C cache/miss short-url
(note-page note-id short-url)))
(cache/lookup @C short-url))))
(GET "/:short-url" [short-url]
(when-let [params (storage/resolve-url short-url)]
@@ -117,7 +118,8 @@
(storage/sign pid psk noteID note password)))]
(if (get-in resp [:status :success])
(do
(swap! C cache/evict noteID)
(doseq [url (storage/get-short-urls noteID)]
(swap! C cache/evict url))
(redirect (:longURL resp)))
(response 403)))
(response 500))))
+4 -1
View File
@@ -98,10 +98,13 @@
(redis :hdel :short-url params)
(redis :hdel :short-url url)))
(defn get-short-urls [noteID]
(redis :smembers (str noteID :urls)))
(defn delete-note [noteID]
(doseq [kw [:password :views :note :published :edited :publisher]]
(redis :hdel kw noteID))
(doseq [url (redis :smembers (str noteID :urls))]
(doseq [url (get-short-urls noteID)]
(delete-short-url url))
(redis :del (str noteID :urls)))