From b992e192ca88aafc5eba088de290d5929e64beb2 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Thu, 2 Oct 2014 22:06:32 -0700 Subject: [PATCH] Speed up homepage. Don't try to fetch repositories to render the homepage (just use the excluded repository count). Also do the user and email address fetches in parallel. --- app/caching_transport.go | 1 + app/githop.go | 42 +++++++++++++++++++++++++++------------- app/templates/index.html | 8 ++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/app/caching_transport.go b/app/caching_transport.go index 1b006b5..c74e7e7 100644 --- a/app/caching_transport.go +++ b/app/caching_transport.go @@ -46,6 +46,7 @@ func (t *CachingTransport) RoundTrip(req *http.Request) (resp *http.Response, er t.Context.Errorf("Error readings bytes for cached response: %v", err) } } + t.Context.Infof("Fetching %s", req.URL) resp, err = t.Transport.RoundTrip(req) if err != nil || resp.StatusCode != 200 { return diff --git a/app/githop.go b/app/githop.go index 6591396..e70c335 100644 --- a/app/githop.go +++ b/app/githop.go @@ -11,6 +11,7 @@ import ( "path/filepath" "strconv" "strings" + "sync" "time" "appengine" @@ -190,29 +191,44 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { oauthTransport.Token = &account.OAuthToken githubClient := github.NewClient(oauthTransport.Client()) - user, _, err := githubClient.Users.Get("") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + var wg sync.WaitGroup + wg.Add(2) + var user *github.User + var userErr error + var emailAddress string + var emailAddressErr error + go func() { + user, _, userErr = githubClient.Users.Get("") + wg.Done() + }() + go func() { + emailAddress, emailAddressErr = account.GetDigestEmailAddress(githubClient) + wg.Done() + }() + wg.Wait() + if userErr != nil { + http.Error(w, userErr.Error(), http.StatusInternalServerError) + return + } + if emailAddressErr != nil { + http.Error(w, emailAddressErr.Error(), http.StatusInternalServerError) return } - repos, err := getRepos(c, githubClient, account, user) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + var repositoryCount string + if len(account.ExcludedRepoIds) > 0 { + repositoryCount = fmt.Sprintf("all but %d", len(account.ExcludedRepoIds)) + } else { + repositoryCount = "all" } - emailAddress, err := account.GetDigestEmailAddress(githubClient) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } var settingsSummary = map[string]interface{}{ "Frequency": account.Frequency, - "RepositoryCount": strconv.Itoa(len(repos.AllRepos) - len(account.ExcludedRepoIds)), + "RepositoryCount": repositoryCount, "EmailAddress": emailAddress, } var data = map[string]interface{}{ + "User": user, "SettingsSummary": settingsSummary, } if err := templates["index"].Execute(w, data); err != nil { diff --git a/app/templates/index.html b/app/templates/index.html index fa22e41..09d06c2 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -3,6 +3,14 @@ {{define "body"}}

+ Signed in as + + {{.User.Login}} + . Sign Out