mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-04 11:05:51 +00:00
Parallelize repository commit fetches.
Also rename Repository struct fields to Repo for brevity.
This commit is contained in:
parent
1a5c6c68c6
commit
057c750f4b
2 changed files with 44 additions and 26 deletions
|
|
@ -21,14 +21,14 @@ import (
|
|||
var router *mux.Router
|
||||
var githubOauthConfig oauth.Config
|
||||
|
||||
type RepositoryDigest struct {
|
||||
Repository *github.Repository
|
||||
Commits []github.RepositoryCommit
|
||||
type RepoDigest struct {
|
||||
Repo *github.Repository
|
||||
Commits []github.RepositoryCommit
|
||||
}
|
||||
|
||||
type Digest struct {
|
||||
User *github.User
|
||||
RepositoryDigests []RepositoryDigest
|
||||
User *github.User
|
||||
RepoDigests []*RepoDigest
|
||||
}
|
||||
|
||||
func initGithubOAuthConfig() {
|
||||
|
|
@ -101,23 +101,41 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
digest := Digest{User: user, RepositoryDigests: make([]RepositoryDigest, 0, len(repos))}
|
||||
for i, repo := range repos {
|
||||
commits, _, err := githubClient.Repositories.ListCommits(
|
||||
*repo.Owner.Login,
|
||||
*repo.Name,
|
||||
&github.CommitsListOptions{
|
||||
Author: *user.Login,
|
||||
Since: digestStartTime,
|
||||
Until: digestEndTime,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(commits) > 0 {
|
||||
digest.RepositoryDigests = append(
|
||||
digest.RepositoryDigests, RepositoryDigest{&repos[i], commits})
|
||||
digest := Digest{User: user, RepoDigests: make([]*RepoDigest, 0, len(repos))}
|
||||
type RepoDigestResponse struct {
|
||||
repoDigest *RepoDigest
|
||||
err error
|
||||
}
|
||||
ch := make(chan *RepoDigestResponse)
|
||||
for _, repo := range repos {
|
||||
go func(repo github.Repository) {
|
||||
commits, _, err := githubClient.Repositories.ListCommits(
|
||||
*repo.Owner.Login,
|
||||
*repo.Name,
|
||||
&github.CommitsListOptions{
|
||||
Author: *user.Login,
|
||||
Since: digestStartTime,
|
||||
Until: digestEndTime,
|
||||
})
|
||||
if err != nil {
|
||||
ch <- &RepoDigestResponse{nil, err}
|
||||
} else {
|
||||
ch <- &RepoDigestResponse{&RepoDigest{&repo, commits}, nil}
|
||||
}
|
||||
}(repo)
|
||||
}
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case r := <-ch:
|
||||
if r.err != nil {
|
||||
http.Error(w, r.err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
digest.RepoDigests = append(digest.RepoDigests, r.repoDigest)
|
||||
if len(digest.RepoDigests) == len(repos) {
|
||||
break loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@
|
|||
|
||||
{{.User.Login}}'s digest:
|
||||
<ul>
|
||||
{{range $index, $repositoryDigest := .RepositoryDigests}}
|
||||
{{range $index, $repoDigest := .RepoDigests}}
|
||||
<li>
|
||||
<a href="https://github.com/{{.Repository.FullName}}">
|
||||
{{.Repository.FullName}}
|
||||
<a href="https://github.com/{{.Repo.FullName}}">
|
||||
{{.Repo.FullName}}
|
||||
</a>
|
||||
<ul>
|
||||
{{range .Commits }}
|
||||
<li>
|
||||
<code><a href="https://github.com/{{$repositoryDigest.Repository.FullName}}/commit/{{.SHA}}">{{.SHA}}</a></code>
|
||||
<code><a href="https://github.com/{{$repoDigest.Repo.FullName}}/commit/{{.SHA}}">{{.SHA}}</a></code>
|
||||
-
|
||||
<i>{{.Commit.Author.Date}}</i>
|
||||
<br>
|
||||
|
|
|
|||
Loading…
Reference in a new issue