Skip to content

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

Merged
merged 1 commit into from
Jun 18, 2023

Conversation

kylecarbs
Copy link
Member

This should reduce the number of API requests a client makes when loading the dashboard dramatically!

@kylecarbs kylecarbs self-assigned this Jun 18, 2023
This should reduce the number of API requests a client makes
when loading the dashboard dramatically!
@kylecarbs
Copy link
Member Author

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!

@kylecarbs kylecarbs merged commit 9df9ad4 into main Jun 18, 2023
@kylecarbs kylecarbs deleted the embedrequests branch June 18, 2023 18:57
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2023
@BrunoQuaresma
Copy link
Collaborator

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"
Copy link
Member

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)
Copy link
Member

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:

  1. Double down on the mux and convert this ServeHTTP into one or more middlewares
  2. 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()
Copy link
Member

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()
Copy link
Member

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
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants