mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Parallelize users admin page requests.
This commit is contained in:
parent
13aa7def19
commit
63070da7fb
1 changed files with 33 additions and 17 deletions
|
|
@ -481,28 +481,44 @@ func usersAdminHandler(w http.ResponseWriter, r *http.Request) *AppError {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return InternalError(err, "Could not look up accounts")
|
return InternalError(err, "Could not look up accounts")
|
||||||
}
|
}
|
||||||
users := make([]map[string]interface{}, len(accounts))
|
|
||||||
|
type AdminUserData struct {
|
||||||
|
Account *Account
|
||||||
|
User *github.User
|
||||||
|
EmailAddress string
|
||||||
|
Repos *Repos
|
||||||
|
ReposError error
|
||||||
|
}
|
||||||
|
ch := make(chan *AdminUserData)
|
||||||
for i := range accounts {
|
for i := range accounts {
|
||||||
account := &accounts[i]
|
go func(account *Account) {
|
||||||
oauthTransport := githubOAuthTransport(c)
|
oauthTransport := githubOAuthTransport(c)
|
||||||
oauthTransport.Token = &account.OAuthToken
|
oauthTransport.Token = &account.OAuthToken
|
||||||
githubClient := github.NewClient(oauthTransport.Client())
|
githubClient := github.NewClient(oauthTransport.Client())
|
||||||
|
|
||||||
user, _, err := githubClient.Users.Get("")
|
user, _, err := githubClient.Users.Get("")
|
||||||
|
|
||||||
emailAddress, err := account.GetDigestEmailAddress(githubClient)
|
emailAddress, err := account.GetDigestEmailAddress(githubClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
emailAddress = err.Error()
|
emailAddress = err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
repos, reposErr := getRepos(c, githubClient, account, user)
|
repos, reposErr := getRepos(c, githubClient, account, user)
|
||||||
|
ch <- &AdminUserData{
|
||||||
|
Account: account,
|
||||||
|
User: user,
|
||||||
|
EmailAddress: emailAddress,
|
||||||
|
Repos: repos,
|
||||||
|
ReposError: reposErr,
|
||||||
|
}
|
||||||
|
}(&accounts[i])
|
||||||
|
}
|
||||||
|
|
||||||
users[i] = map[string]interface{}{
|
users := make([]*AdminUserData, 0)
|
||||||
"Account": account,
|
for _ = range accounts {
|
||||||
"User": user,
|
select {
|
||||||
"EmailAddress": emailAddress,
|
case r := <-ch:
|
||||||
"Repos": repos,
|
users = append(users, r)
|
||||||
"ReposError": reposErr,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var data = map[string]interface{}{
|
var data = map[string]interface{}{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue