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.
This commit is contained in:
Mihai Parparita 2014-10-02 22:06:32 -07:00
parent cd88fad2ac
commit b992e192ca
3 changed files with 38 additions and 13 deletions

View file

@ -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.Errorf("Error readings bytes for cached response: %v", err)
} }
} }
t.Context.Infof("Fetching %s", req.URL)
resp, err = t.Transport.RoundTrip(req) resp, err = t.Transport.RoundTrip(req)
if err != nil || resp.StatusCode != 200 { if err != nil || resp.StatusCode != 200 {
return return

View file

@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"appengine" "appengine"
@ -190,29 +191,44 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
oauthTransport.Token = &account.OAuthToken oauthTransport.Token = &account.OAuthToken
githubClient := github.NewClient(oauthTransport.Client()) githubClient := github.NewClient(oauthTransport.Client())
user, _, err := githubClient.Users.Get("") var wg sync.WaitGroup
if err != nil { wg.Add(2)
http.Error(w, err.Error(), http.StatusInternalServerError) 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 return
} }
repos, err := getRepos(c, githubClient, account, user) var repositoryCount string
if err != nil { if len(account.ExcludedRepoIds) > 0 {
http.Error(w, err.Error(), http.StatusInternalServerError) repositoryCount = fmt.Sprintf("all but %d", len(account.ExcludedRepoIds))
return } else {
repositoryCount = "all"
} }
emailAddress, err := account.GetDigestEmailAddress(githubClient)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var settingsSummary = map[string]interface{}{ var settingsSummary = map[string]interface{}{
"Frequency": account.Frequency, "Frequency": account.Frequency,
"RepositoryCount": strconv.Itoa(len(repos.AllRepos) - len(account.ExcludedRepoIds)), "RepositoryCount": repositoryCount,
"EmailAddress": emailAddress, "EmailAddress": emailAddress,
} }
var data = map[string]interface{}{ var data = map[string]interface{}{
"User": user,
"SettingsSummary": settingsSummary, "SettingsSummary": settingsSummary,
} }
if err := templates["index"].Execute(w, data); err != nil { if err := templates["index"].Execute(w, data); err != nil {

View file

@ -3,6 +3,14 @@
{{define "body"}} {{define "body"}}
<p> <p>
Signed in as
<a href="https://github.com/{{.User.Login}}"
title="{{.User.Name}}">
<img src="{{.User.AvatarURL}}"
width="20"
height="20"
border="0">{{.User.Login}}
</a>.
<a href="{{routeUrl "sign-out"}}"> <a href="{{routeUrl "sign-out"}}">
Sign Out Sign Out
</a> </a>