parallelize beatmap name retrieval
This commit is contained in:
parent
9183914420
commit
d00856807e
2 changed files with 32 additions and 7 deletions
|
@ -14,11 +14,24 @@
|
|||
|
||||
<p>Maps:</p>
|
||||
|
||||
<ul class="list-disc">
|
||||
<table class="table-auto">
|
||||
<thead>
|
||||
<th>Mapper</th>
|
||||
<th>Artist</th>
|
||||
<th>Title</th>
|
||||
<th>Links</th>
|
||||
</thead>
|
||||
{{ range .Beatmapsets }}
|
||||
<li><a href="https://osu.ppy.sh/s/{{ .ID }}" class="underline">{{ .Artist }} - {{ .Title }}</a></li>
|
||||
<tbody>
|
||||
<td>{{ .Creator }}</td>
|
||||
<td>{{ .Artist }}</td>
|
||||
<td>{{ .Title }}</td>
|
||||
<td>
|
||||
<a href="https://osu.ppy.sh/s/{{ .ID }}" class="underline">osu</a>
|
||||
</td>
|
||||
</tbody>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
20
web/web.go
20
web/web.go
|
@ -10,6 +10,7 @@ import (
|
|||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/foolin/goview"
|
||||
|
@ -123,7 +124,7 @@ func RunWeb(config *config.Config, api *osuapi.Osuapi) {
|
|||
|
||||
func getRepos(config *config.Config, api *osuapi.Osuapi) []osuapi.Beatmapset {
|
||||
expensive := func() (interface{}, error) {
|
||||
repos := make([]osuapi.Beatmapset, 0)
|
||||
repos := make([]int, 0)
|
||||
reposDir := config.Repos
|
||||
users, _ := ioutil.ReadDir(reposDir)
|
||||
|
||||
|
@ -137,12 +138,23 @@ func getRepos(config *config.Config, api *osuapi.Osuapi) []osuapi.Beatmapset {
|
|||
fmt.Println(mapDir)
|
||||
|
||||
id, _ := strconv.Atoi(mapId.Name())
|
||||
bs, _ := api.GetBeatmapSet(id)
|
||||
repos = append(repos, bs)
|
||||
repos = append(repos, id)
|
||||
}
|
||||
}
|
||||
|
||||
return repos, nil
|
||||
beatmapSets := make([]osuapi.Beatmapset, len(repos))
|
||||
var wg sync.WaitGroup
|
||||
for i, repo := range repos {
|
||||
wg.Add(1)
|
||||
go func(i int, repo int) {
|
||||
bs, _ := api.GetBeatmapSet(repo)
|
||||
beatmapSets[i] = bs
|
||||
wg.Done()
|
||||
}(i, repo)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
return beatmapSets, nil
|
||||
}
|
||||
|
||||
result, _, _ := cache.Memoize("key1", expensive)
|
||||
|
|
Loading…
Reference in a new issue