mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +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 router *mux.Router
|
||||||
var githubOauthConfig oauth.Config
|
var githubOauthConfig oauth.Config
|
||||||
|
|
||||||
type RepositoryDigest struct {
|
type RepoDigest struct {
|
||||||
Repository *github.Repository
|
Repo *github.Repository
|
||||||
Commits []github.RepositoryCommit
|
Commits []github.RepositoryCommit
|
||||||
}
|
}
|
||||||
|
|
||||||
type Digest struct {
|
type Digest struct {
|
||||||
User *github.User
|
User *github.User
|
||||||
RepositoryDigests []RepositoryDigest
|
RepoDigests []*RepoDigest
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGithubOAuthConfig() {
|
func initGithubOAuthConfig() {
|
||||||
|
|
@ -101,23 +101,41 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
digest := Digest{User: user, RepositoryDigests: make([]RepositoryDigest, 0, len(repos))}
|
digest := Digest{User: user, RepoDigests: make([]*RepoDigest, 0, len(repos))}
|
||||||
for i, repo := range repos {
|
type RepoDigestResponse struct {
|
||||||
commits, _, err := githubClient.Repositories.ListCommits(
|
repoDigest *RepoDigest
|
||||||
*repo.Owner.Login,
|
err error
|
||||||
*repo.Name,
|
}
|
||||||
&github.CommitsListOptions{
|
ch := make(chan *RepoDigestResponse)
|
||||||
Author: *user.Login,
|
for _, repo := range repos {
|
||||||
Since: digestStartTime,
|
go func(repo github.Repository) {
|
||||||
Until: digestEndTime,
|
commits, _, err := githubClient.Repositories.ListCommits(
|
||||||
})
|
*repo.Owner.Login,
|
||||||
if err != nil {
|
*repo.Name,
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
&github.CommitsListOptions{
|
||||||
return
|
Author: *user.Login,
|
||||||
}
|
Since: digestStartTime,
|
||||||
if len(commits) > 0 {
|
Until: digestEndTime,
|
||||||
digest.RepositoryDigests = append(
|
})
|
||||||
digest.RepositoryDigests, RepositoryDigest{&repos[i], commits})
|
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:
|
{{.User.Login}}'s digest:
|
||||||
<ul>
|
<ul>
|
||||||
{{range $index, $repositoryDigest := .RepositoryDigests}}
|
{{range $index, $repoDigest := .RepoDigests}}
|
||||||
<li>
|
<li>
|
||||||
<a href="https://github.com/{{.Repository.FullName}}">
|
<a href="https://github.com/{{.Repo.FullName}}">
|
||||||
{{.Repository.FullName}}
|
{{.Repo.FullName}}
|
||||||
</a>
|
</a>
|
||||||
<ul>
|
<ul>
|
||||||
{{range .Commits }}
|
{{range .Commits }}
|
||||||
<li>
|
<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>
|
<i>{{.Commit.Author.Date}}</i>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue