From 1ba3b408d5f81422a34ad83e4dcf9e786a02b390 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Mon, 31 Mar 2014 09:52:15 +0200 Subject: [PATCH] bugfix: ui caching disabled short urls --- LANDING.md | 2 +- src/notehub/handler.clj | 16 +++++++++------- src/notehub/storage.clj | 5 ++++- test/notehub/test/handler.clj | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/LANDING.md b/LANDING.md index 93e9737..a383364 100644 --- a/LANDING.md +++ b/LANDING.md @@ -3,7 +3,7 @@ - [Dark](/2014/3/31/demo-note?theme=dark) - [Solarized-Dark](/2014/3/31/demo-note?theme=solarized-dark) - [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. - **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). diff --git a/src/notehub/handler.clj b/src/notehub/handler.clj index b5297bb..01c0ac5 100644 --- a/src/notehub/handler.clj +++ b/src/notehub/handler.clj @@ -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)))) diff --git a/src/notehub/storage.clj b/src/notehub/storage.clj index dced2c1..779f822 100644 --- a/src/notehub/storage.clj +++ b/src/notehub/storage.clj @@ -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))) diff --git a/test/notehub/test/handler.clj b/test/notehub/test/handler.clj index 2542818..9973497 100644 --- a/test/notehub/test/handler.clj +++ b/test/notehub/test/handler.clj @@ -124,7 +124,7 @@ (testing "main route" (let [response (app (request :get "/"))] (is (= (:status response) 200)) - (is (substring? "free and hassle-free" (:body response))))) + (is (substring? "Free and Hassle-free" (:body response))))) (testing "not-found route" (let [response (app (request :get "/invalid"))]