Skip to content

Commit

Permalink
Count without channels
Browse files Browse the repository at this point in the history
  • Loading branch information
ResamVi committed May 5, 2023
1 parent a21e483 commit 16f53c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions backend/fetch/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func getServers() ([]klei.Server, error) {
log.Infof("Found %v servers", len(lobby))

// Collect the details (player info etc.) of each server.
servers, count := klei.Servers(lobby, region)
servers := klei.Servers(lobby, region)
result = append(result, servers...)

log.Infof("Parsed in %.2fs with %v/%v failing", time.Since(start).Seconds(), count, len(servers))
log.Infof("Parsed in %.2fs with %v/%v failing", time.Since(start).Seconds(), len(lobby)-len(servers), len(lobby))
}

return result, nil
Expand Down
11 changes: 2 additions & 9 deletions backend/fetch/klei/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ func (d Server) Location(geoip *geoip2.Reader) (string, string, string) {
return record.Country.Names["en"], record.Continent.Names["en"], record.Country.IsoCode
}

func Servers(lobby []LobbyEntry, region string) ([]Server, int) {
func Servers(lobby []LobbyEntry, region string) []Server {
var result []Server

wp := workerpool.New(1000)

ch := make(chan struct{}, len(lobby))
for _, entry := range lobby {
wp.Submit(func() {
details, err := readEntry(entry, region)
if err != nil {
ch <- struct{}{}
return
}

Expand All @@ -83,12 +81,7 @@ func Servers(lobby []LobbyEntry, region string) ([]Server, int) {
wp.StopWait()

// Atomic counter did not work. Poor try at counting errors.
count := 0
for len(ch) > 0 {
count++
}

return result, count
return result
}

// token as per https://forums.kleientertainment.com/forums/topic/115578-retrieving-dst-server-data
Expand Down

0 comments on commit 16f53c6

Please sign in to comment.