Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotserver: calculate repoindex items in parallel

performing rev-list and filetree in sequential occupy a large amount of
the client budget. we can parallelize all these expensive operations.

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
2c03f426 d4f57e8d

+71 -28
+71 -28
knotserver/routes.go
··· 17 17 "path/filepath" 18 18 "strconv" 19 19 "strings" 20 + "sync" 20 21 21 22 securejoin "github.com/cyphar/filepath-securejoin" 22 23 "github.com/gliderlabs/ssh" ··· 89 88 } 90 89 } 91 90 92 - commits, err := gr.Commits(0, 60) // a good preview of commits in this repo 93 - if err != nil { 94 - writeError(w, err.Error(), http.StatusInternalServerError) 95 - l.Error("fetching commits", "error", err.Error()) 96 - return 97 - } 91 + var ( 92 + commits []*object.Commit 93 + total int 94 + branches []types.Branch 95 + files []types.NiceTree 96 + tags []*git.TagReference 97 + ) 98 98 99 - total, err := gr.TotalCommits() 100 - if err != nil { 101 - writeError(w, err.Error(), http.StatusInternalServerError) 102 - l.Error("fetching commits", "error", err.Error()) 103 - return 104 - } 99 + var wg sync.WaitGroup 100 + errorsCh := make(chan error, 5) 105 101 106 - branches, err := gr.Branches() 107 - if err != nil { 108 - l.Error("getting branches", "error", err.Error()) 102 + wg.Add(1) 103 + go func() { 104 + defer wg.Done() 105 + cs, err := gr.Commits(0, 60) 106 + if err != nil { 107 + errorsCh <- fmt.Errorf("commits: %w", err) 108 + return 109 + } 110 + commits = cs 111 + }() 112 + 113 + wg.Add(1) 114 + go func() { 115 + defer wg.Done() 116 + t, err := gr.TotalCommits() 117 + if err != nil { 118 + errorsCh <- fmt.Errorf("calculating total: %w", err) 119 + return 120 + } 121 + total = t 122 + }() 123 + 124 + wg.Add(1) 125 + go func() { 126 + defer wg.Done() 127 + bs, err := gr.Branches() 128 + if err != nil { 129 + errorsCh <- fmt.Errorf("fetching branches: %w", err) 130 + return 131 + } 132 + branches = bs 133 + }() 134 + 135 + wg.Add(1) 136 + go func() { 137 + defer wg.Done() 138 + ts, err := gr.Tags() 139 + if err != nil { 140 + errorsCh <- fmt.Errorf("fetching tags: %w", err) 141 + return 142 + } 143 + tags = ts 144 + }() 145 + 146 + wg.Add(1) 147 + go func() { 148 + defer wg.Done() 149 + fs, err := gr.FileTree(r.Context(), "") 150 + if err != nil { 151 + errorsCh <- fmt.Errorf("fetching filetree: %w", err) 152 + return 153 + } 154 + files = fs 155 + }() 156 + 157 + wg.Wait() 158 + close(errorsCh) 159 + 160 + // show any errors 161 + for err := range errorsCh { 162 + l.Error("loading repo", "error", err.Error()) 109 163 writeError(w, err.Error(), http.StatusInternalServerError) 110 164 return 111 - } 112 - 113 - tags, err := gr.Tags() 114 - if err != nil { 115 - // Non-fatal, we *should* have at least one branch to show. 116 - l.Warn("getting tags", "error", err.Error()) 117 165 } 118 166 119 167 rtags := []*types.TagReference{} ··· 191 141 readmeContent = string(content) 192 142 readmeFile = readme 193 143 } 194 - } 195 - 196 - files, err := gr.FileTree(r.Context(), "") 197 - if err != nil { 198 - writeError(w, err.Error(), http.StatusInternalServerError) 199 - l.Error("file tree", "error", err.Error()) 200 - return 201 144 } 202 145 203 146 if ref == "" {