This commit is contained in:
+3
-15
@@ -12,7 +12,6 @@ import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -127,26 +126,15 @@ func (s *SearchService) SearchMedia(queries []string, enabledPlatforms map[strin
|
||||
}
|
||||
|
||||
func (s *SearchService) EnrichResults(results []SearchResult) []SearchResult {
|
||||
limit := minInt(len(results), 18)
|
||||
if limit == 0 {
|
||||
if len(results) == 0 {
|
||||
return results
|
||||
}
|
||||
|
||||
enriched := make([]SearchResult, len(results))
|
||||
copy(enriched, results)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
sem := make(chan struct{}, 4)
|
||||
for idx := 0; idx < limit; idx++ {
|
||||
wg.Add(1)
|
||||
go func(i int) {
|
||||
defer wg.Done()
|
||||
sem <- struct{}{}
|
||||
defer func() { <-sem }()
|
||||
enriched[i] = s.enrichResult(enriched[i])
|
||||
}(idx)
|
||||
for idx := range enriched {
|
||||
enriched[idx] = s.enrichResult(enriched[idx])
|
||||
}
|
||||
wg.Wait()
|
||||
return enriched
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user