This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-22
Channels
- # announcements (28)
- # babashka (77)
- # beginners (122)
- # calva (40)
- # circleci (3)
- # clj-kondo (47)
- # cljs-dev (9)
- # clojure (119)
- # clojure-australia (1)
- # clojure-europe (88)
- # clojure-nl (3)
- # clojure-uk (33)
- # code-reviews (64)
- # core-logic (37)
- # cursive (10)
- # datomic (13)
- # emacs (1)
- # fulcro (4)
- # graalvm (1)
- # graphql (5)
- # helix (4)
- # integrant (25)
- # jobs (1)
- # jobs-rus (1)
- # off-topic (3)
- # pathom (12)
- # random (1)
- # re-frame (48)
- # reagent (1)
- # remote-jobs (1)
- # reveal (1)
- # rewrite-clj (4)
- # ring (6)
- # ring-swagger (1)
- # shadow-cljs (21)
- # sql (8)
- # tools-deps (25)
- # vim (15)
- # xtdb (12)
version 1 is ready. so please some more feedback https://github.com/RoelofWobben/paintings
I like this, the separate namespace and refactoring for html generation helps a lot
the only thing that bugging me is that it takes some 4 seconds before a page is loaded
is the remote resource being queried when you generate every response?
one alternative is to have a startup step that pre-caches (so instead of sitting idle and doing the work when the first request comes in, it can do it immediately)
for simple things where you just want something to run in the background and don't care if it fails or what it returns, you can just replace (f x)
with (future (f x))
so you could use a future to ensure the next page is pre-fetching in cache, when this page is asked for
unless I am misunderstanding you that's pretty simple - clojure functions have an implicit "do" block so you can add side-effecting code before the part where it returns something
but in your case this might mean moving some logic out of the router itself into a function
(the router syntax sugar might be making what the code actually does less clear)
the router only calls some functions and as far as I understand things does not have some logic
(defroutes app
(GET "/" request (let [page (extract-page-number request)]
(-> (memo-display-data page)
(display/generate-html page))))
...)
this is weird because it's creating an implicit function inline
I guess you can still sneak a prefetch in
(defroutes app
(GET "/" request (let [page (extract-page-number request)]
(future (pre-fetch page))
(-> (memo-display-data page)
(display/generate-html page))))
...)
that's not clojure it's defroutes
everything after Get "/"
is using a compojure dsl to implicitly create a function
I'd normally have
(defn home-handler
[request]
(let [page (extract-page-number request)]
(-> (memo-display-data page)
(display/generate-html page))))
(defroutes app
(GET "/" home-handler))
it's a style choice, but I think beyond a line or two it's better to explicitly use a function
what you might want is just (future (memo-display-data (inc page))
I just hand't filled out that part yet, so I used an imaginary function name
Thanks. I will sleep about it Right now this is im afraid more then I already know about clojure and it is late here
so if I understand you well the handler has to look like this :
(defn home-handler
[request]
(let [page (extract-page-number request)]
(-> (future(memo-display-data (inc page))
(display/generate-html page))))
(defroutes app
(GET "/" home-handler))
why is the future inside the ->
you don't care what it returns (or even if it succeeds) when you are doing a prefetch
(defn home-handler
[request]
(let [page (extract-page-number request)]
(future (memo-display-data (inc page))
(-> (memo-display-data page)
(display/generate-html page))))
the future is being done for side effects, so it shouldn't be inside the chain
if it fails, you can deal with that next time (it won't get memoized, you'll see the actual error), so you can just fire and forget to preload cache
but I see now this error : 2021-01-22 23:24:45.403:WARN:oejs.HttpChannel:qtp1199115300-24: / java.lang.NullPointerException: Response map is nil at ring.util.servlet$update_servlet_response.invokeStatic(servlet.clj:100) at ring.util.servlet$update_servlet_response.invoke(servlet.clj:91) at ring.util.servlet$update_servlet_response.invokeStatic(servlet.clj:95) at ring.util.servlet$update_servlet_response.invoke(servlet.clj:91) at ring.adapter.jetty$proxy_handler$fn__7287.invoke(jetty.clj:28) at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:501) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273) at http://org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at http://org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) at http://org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) at java.base/java.lang.Thread.run(Thread.java:834)
@noisesmith any idea why I know get a error message that there is a empty respons map
what does the code look like currently?
@U01JARXUA75 and I solved it. We found 2 small issues with my code
next would be to make the layout in react so I can make the images clickable and I can show a modal with some more info about the paintings
aha, so the templates all move from server side code into client side