bugfix: ui caching disabled short urls
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
- [Dark](/2014/3/31/demo-note?theme=dark)
|
- [Dark](/2014/3/31/demo-note?theme=dark)
|
||||||
- [Solarized-Dark](/2014/3/31/demo-note?theme=solarized-dark)
|
- [Solarized-Dark](/2014/3/31/demo-note?theme=solarized-dark)
|
||||||
- [Solarized-Light](/2014/3/31/demo-note?theme=solarized-light)
|
- [Solarized-Light](/2014/3/31/demo-note?theme=solarized-light)
|
||||||
- **Fonts**: specify a font (also one of the [Google Web Fonts](http://www.google.com/webfonts/)) for headers and for the text by appending parameters to the note [URL](/p65k1).
|
- **Fonts**: specify a font (also one of the [Google Web Fonts](http://www.google.com/webfonts/)) for headers and for the text by appending parameters to the note [URL](/q9pqq).
|
||||||
- **Short URLs**: every page (including theme & font options) has its own short url.
|
- **Short URLs**: every page (including theme & font options) has its own short url.
|
||||||
- **Editing**: if you set a password during publishing, you can edit your note any time later.
|
- **Editing**: if you set a password during publishing, you can edit your note any time later.
|
||||||
- **Statistics**: a rudimentary statistics available (date of publishing & view counter).
|
- **Statistics**: a rudimentary statistics available (date of publishing & view counter).
|
||||||
|
|||||||
@@ -74,15 +74,16 @@
|
|||||||
(GET "/:year/:month/:day/:title" [year month day title :as params]
|
(GET "/:year/:month/:day/:title" [year month day title :as params]
|
||||||
(let [params (assoc (:query-params params)
|
(let [params (assoc (:query-params params)
|
||||||
:year year :month month :day day :title title)
|
: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)
|
(when (storage/note-exists? note-id)
|
||||||
(if (cache/has? @C note-id)
|
(if (cache/has? @C short-url)
|
||||||
(do
|
(do
|
||||||
(swap! C cache/hit note-id)
|
(swap! C cache/hit short-url)
|
||||||
(storage/increment-note-view note-id))
|
(storage/increment-note-view note-id))
|
||||||
(swap! C cache/miss note-id
|
(swap! C cache/miss short-url
|
||||||
(note-page note-id (storage/create-short-url note-id params))))
|
(note-page note-id short-url)))
|
||||||
(cache/lookup @C note-id))))
|
(cache/lookup @C short-url))))
|
||||||
|
|
||||||
(GET "/:short-url" [short-url]
|
(GET "/:short-url" [short-url]
|
||||||
(when-let [params (storage/resolve-url short-url)]
|
(when-let [params (storage/resolve-url short-url)]
|
||||||
@@ -117,7 +118,8 @@
|
|||||||
(storage/sign pid psk noteID note password)))]
|
(storage/sign pid psk noteID note password)))]
|
||||||
(if (get-in resp [:status :success])
|
(if (get-in resp [:status :success])
|
||||||
(do
|
(do
|
||||||
(swap! C cache/evict noteID)
|
(doseq [url (storage/get-short-urls noteID)]
|
||||||
|
(swap! C cache/evict url))
|
||||||
(redirect (:longURL resp)))
|
(redirect (:longURL resp)))
|
||||||
(response 403)))
|
(response 403)))
|
||||||
(response 500))))
|
(response 500))))
|
||||||
|
|||||||
@@ -98,10 +98,13 @@
|
|||||||
(redis :hdel :short-url params)
|
(redis :hdel :short-url params)
|
||||||
(redis :hdel :short-url url)))
|
(redis :hdel :short-url url)))
|
||||||
|
|
||||||
|
(defn get-short-urls [noteID]
|
||||||
|
(redis :smembers (str noteID :urls)))
|
||||||
|
|
||||||
(defn delete-note [noteID]
|
(defn delete-note [noteID]
|
||||||
(doseq [kw [:password :views :note :published :edited :publisher]]
|
(doseq [kw [:password :views :note :published :edited :publisher]]
|
||||||
(redis :hdel kw noteID))
|
(redis :hdel kw noteID))
|
||||||
(doseq [url (redis :smembers (str noteID :urls))]
|
(doseq [url (get-short-urls noteID)]
|
||||||
(delete-short-url url))
|
(delete-short-url url))
|
||||||
(redis :del (str noteID :urls)))
|
(redis :del (str noteID :urls)))
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@
|
|||||||
(testing "main route"
|
(testing "main route"
|
||||||
(let [response (app (request :get "/"))]
|
(let [response (app (request :get "/"))]
|
||||||
(is (= (:status response) 200))
|
(is (= (:status response) 200))
|
||||||
(is (substring? "free and hassle-free" (:body response)))))
|
(is (substring? "Free and Hassle-free" (:body response)))))
|
||||||
|
|
||||||
(testing "not-found route"
|
(testing "not-found route"
|
||||||
(let [response (app (request :get "/invalid"))]
|
(let [response (app (request :get "/invalid"))]
|
||||||
|
|||||||
Reference in New Issue
Block a user