Browse Source

bugfix: ui caching disabled short urls

master
Christian Mueller 12 years ago
parent
commit
1ba3b408d5
  1. 2
      LANDING.md
  2. 16
      src/notehub/handler.clj
  3. 5
      src/notehub/storage.clj
  4. 2
      test/notehub/test/handler.clj

2
LANDING.md

@ -3,7 +3,7 @@ @@ -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).

16
src/notehub/handler.clj

@ -74,15 +74,16 @@ @@ -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 @@ @@ -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))))

5
src/notehub/storage.clj

@ -98,10 +98,13 @@ @@ -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)))

2
test/notehub/test/handler.clj

@ -124,7 +124,7 @@ @@ -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"))]

Loading…
Cancel
Save