Skip to content
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

add context param query cache #1450

Merged
merged 3 commits into from
May 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type Context struct {

// Accepted defines a list of manually accepted formats for content negotiation.
Accepted []string

// queryCache use url.ParseQuery cached the param query result from c.Request.URL.Query()
queryCache url.Values
}

/************************************/
Expand All @@ -75,6 +78,7 @@ func (c *Context) reset() {
c.Keys = nil
c.Errors = c.Errors[0:0]
c.Accepted = nil
c.queryCache = nil
}

// Copy returns a copy of the current context that can be safely used outside the request's scope.
Expand Down Expand Up @@ -385,7 +389,13 @@ func (c *Context) QueryArray(key string) []string {
// GetQueryArray returns a slice of strings for a given query key, plus
// a boolean value whether at least one value exists for the given key.
func (c *Context) GetQueryArray(key string) ([]string, bool) {
if values, ok := c.Request.URL.Query()[key]; ok && len(values) > 0 {

if c.queryCache == nil {
c.queryCache = make(url.Values)
c.queryCache, _ = url.ParseQuery(c.Request.URL.RawQuery)
}

if values, ok := c.queryCache[key]; ok && len(values) > 0 {
return values, true
}
return []string{}, false
Expand Down