Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(41)

Unified Diff: store/server.go

Issue 6063043: store: increment stats counters in the background
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « [revision details] ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: store/server.go
=== modified file 'store/server.go'
--- store/server.go 2012-04-17 13:26:13 +0000
+++ store/server.go 2012-04-17 14:12:24 +0000
@@ -55,6 +55,13 @@
return req.Form.Get("stats") != "0"
}
+func charmStatsKey(curl *charm.URL, kind string) []string {
+ if curl.User == "" {
+ return []string{kind, curl.Series, curl.Name}
+ }
+ return []string{kind, curl.Series, curl.Name, curl.User}
+}
+
func (s *Server) serveInfo(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/charm-info" {
w.WriteHeader(http.StatusNotFound)
@@ -72,25 +79,17 @@
}
var skey []string
if err == nil {
- if curl.User == "" {
- skey = []string{"charm-info", curl.Series, curl.Name}
- } else {
- skey = []string{"charm-info", curl.Series, curl.Name, curl.User}
- }
+ skey = charmStatsKey(curl, "charms-info")
c.Sha256 = info.BundleSha256()
c.Revision = info.Revision()
} else {
if err == ErrNotFound {
- if curl.User == "" {
- skey = []string{"charm-missing", curl.Series, curl.Name}
- } else {
- skey = []string{"charm-missing", curl.Series, curl.Name, curl.User}
- }
+ skey = charmStatsKey(curl, "charm-missing")
}
c.Errors = append(c.Errors, err.Error())
}
if skey != nil && statsEnabled(r) {
- s.store.IncCounter(skey)
+ go s.store.IncCounter(skey)
}
}
data, err := json.Marshal(response)
@@ -125,11 +124,7 @@
return
}
if statsEnabled(r) {
- if curl.User == "" {
- s.store.IncCounter([]string{"charm-bundle", curl.Series, curl.Name})
- } else {
- s.store.IncCounter([]string{"charm-bundle", curl.Series, curl.Name, curl.User})
- }
+ go s.store.IncCounter(charmStatsKey(curl, "charm-bundle"))
}
defer rc.Close()
w.Header().Set("Connection", "close") // No keep-alive for now.
« no previous file with comments | « [revision details] ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 204d58d