mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-03-25 09:25:49 +00:00
Start a background task to compute the digest as soon as the timezone is set.
Serves as a cache warmup, for cases where the user views their digest immediately.
This commit is contained in:
parent
b4947769ad
commit
b96671fffd
1 changed files with 29 additions and 0 deletions
|
|
@ -545,8 +545,37 @@ func setInitialTimezoneHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Since we've now computed an initial timezone for the user, start a
|
||||
// background task to compute their digest. This ensures that we have most
|
||||
// of the relevant data already cached if they choose to view or email their
|
||||
// digest immediately.
|
||||
cacheDigestForAccountFunc.Call(c, account.GitHubUserId)
|
||||
}
|
||||
|
||||
var cacheDigestForAccountFunc = delay.Func(
|
||||
"cacheDigestForAccount",
|
||||
func(c appengine.Context, githubUserId int) error {
|
||||
c.Infof("Caching digest for %d...", githubUserId)
|
||||
account, err := getAccount(c, githubUserId)
|
||||
if err != nil {
|
||||
c.Errorf(" Error looking up account: %s", err.Error())
|
||||
// Not returning error since we don't want these tasks to be
|
||||
// retried.
|
||||
return nil
|
||||
}
|
||||
|
||||
oauthTransport := githubOAuthTransport(c)
|
||||
oauthTransport.Token = &account.OAuthToken
|
||||
githubClient := github.NewClient(oauthTransport.Client())
|
||||
_, err = newDigest(c, githubClient, account)
|
||||
if err != nil {
|
||||
c.Errorf(" Error computing digest: %s", err.Error())
|
||||
}
|
||||
c.Infof(" Done!")
|
||||
return nil
|
||||
})
|
||||
|
||||
func deleteAccountHandler(w http.ResponseWriter, r *http.Request) {
|
||||
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
||||
userId := session.Values[sessionConfig.UserIdKey].(int)
|
||||
|
|
|
|||
Loading…
Reference in a new issue