-
Notifications
You must be signed in to change notification settings - Fork 928
feat: embed common client requests into the template html #8076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This should reduce the number of API requests a client makes when loading the dashboard dramatically!
Force merging this to see it on dev.coder.com (I'm excited about it). If anyone finds anything post-merge, just comment and I'll fix! |
Maybe one thing we can do to simplify is only have one tag called "state" or "initialData" that has all these info into a single JSON so we can have only one function that parses that and return the data instead of having them in multiple places. |
@@ -5,8 +5,11 @@ import ( | |||
"encoding/json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good new package
switch { | ||
// If requesting binaries, serve straight up. | ||
case reqFile == "bin" || strings.HasPrefix(reqFile, "bin/"): | ||
h.handler.ServeHTTP(rw, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way the Handler
sits atop an inner handler
is confusing to me. It's not clear where the responsibilities are separate. I think the code would be clearer if one of two paths were taken:
- Double down on the mux and convert this ServeHTTP into one or more middlewares
- Get rid of the mux entirely and call out to a
http.FileServer
here- For a simple server, a big switch case is more readable than the mux/middleware pattern
orgIDs = memberIDs[0].OrganizationIDs | ||
return err | ||
}) | ||
err := eg.Wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this pattern duplicated, we should consider bringing in code like https://github.com/ammario/promise/blob/main/promise.go to improve maintainability and correctness. The errgroup method means you have to wait for both goroutines to finish before using either value.
} | ||
} | ||
|
||
return API.getAppearance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why fallback to API? when would the value not be injected in the HTML?
return nil | ||
} | ||
if err != nil { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is on purpose it deserves a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair
This should reduce the number of API requests a client makes when loading the dashboard dramatically!