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>
|
<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 }}
|
{{ 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 }}
|
{{ end }}
|
||||||
</ul>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
20
web/web.go
20
web/web.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/foolin/goview"
|
"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 {
|
func getRepos(config *config.Config, api *osuapi.Osuapi) []osuapi.Beatmapset {
|
||||||
expensive := func() (interface{}, error) {
|
expensive := func() (interface{}, error) {
|
||||||
repos := make([]osuapi.Beatmapset, 0)
|
repos := make([]int, 0)
|
||||||
reposDir := config.Repos
|
reposDir := config.Repos
|
||||||
users, _ := ioutil.ReadDir(reposDir)
|
users, _ := ioutil.ReadDir(reposDir)
|
||||||
|
|
||||||
|
@ -137,12 +138,23 @@ func getRepos(config *config.Config, api *osuapi.Osuapi) []osuapi.Beatmapset {
|
||||||
fmt.Println(mapDir)
|
fmt.Println(mapDir)
|
||||||
|
|
||||||
id, _ := strconv.Atoi(mapId.Name())
|
id, _ := strconv.Atoi(mapId.Name())
|
||||||
bs, _ := api.GetBeatmapSet(id)
|
repos = append(repos, id)
|
||||||
repos = append(repos, bs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
result, _, _ := cache.Memoize("key1", expensive)
|
||||||
|
|
Loading…
Reference in a new issue