Przeglądaj źródła

Fetch the most expensive info in parallel

Operations that need to walk the history are run in parallel, in
particular the last-commit-per-file info is obtained in parallel.  This
cuts down our response rate drastically, although it's still way too
high.
Lucas Stadler 8 lat temu
rodzic
commit
0172c19083
1 zmienionych plików z 49 dodań i 1 usunięć
  1. 49 1
      quit.go

+ 49 - 1
quit.go

@ -13,6 +13,7 @@ import (
13 13
	"path/filepath"
14 14
	"sort"
15 15
	"strings"
16
	"sync"
16 17
	"time"
17 18
18 19
	"github.com/libgit2/git2go"
@ -42,11 +43,58 @@ func main() {
42 43
	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
43 44
		performance.MeasureRequest(req)
44 45
46
		handleError := func(w http.ResponseWriter, err error) {
47
			log.Println("git: ", err)
48
			http.Error(w, "internal server error", http.StatusInternalServerError)
49
		}
50
51
		fancyRepo := NewFancyRepo(repo)
52
		commit, err := fancyRepo.Commit()
53
		if err != nil {
54
			handleError(w, err)
55
			return
56
		}
57
		files, err := commit.Files(false)
58
		if err != nil {
59
			handleError(w, err)
60
			return
61
		}
62
63
		var wg sync.WaitGroup
64
		wg.Add(len(files))
65
		for _, f := range files {
66
			go func(f *FancyFile) {
67
				defer wg.Done()
68
69
				_, err := f.Commit()
70
				if err != nil {
71
					handleError(w, err)
72
				}
73
			}(f)
74
		}
75
76
		wg.Add(2)
77
		go func() {
78
			defer wg.Done()
79
			_, err := fancyRepo.CommitCount()
80
			if err != nil {
81
				handleError(w, err)
82
			}
83
		}()
84
		go func() {
85
			defer wg.Done()
86
			_, err := fancyRepo.Contributors()
87
			if err != nil {
88
				handleError(w, err)
89
			}
90
		}()
91
		wg.Wait()
92
45 93
		buf := new(bytes.Buffer)
46 94
		start := time.Now()
47 95
		err = repoTmpl.Execute(buf, map[string]interface{}{
48 96
			"RepoPath":    path.Base(repoPath),
49
			"Repo":        NewFancyRepo(repo),
97
			"Repo":        fancyRepo,
50 98
			"Style":       template.CSS(repoStyle),
51 99
			"Performance": performance.Render(req),
52 100
		})