From d4dbb47ac776471eb8a9f91a97da40b9b6621a74 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 21 May 2023 14:44:33 +0200 Subject: paralyze searching --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 420ade8..94e11b9 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "net/http" "strings" + "time" "muhq.space/go/wrms/llog" @@ -36,7 +37,16 @@ func searchHandler(w http.ResponseWriter, r *http.Request) { llog.Debug("Searching for %s", pattern) - results := wrms.Player.Search(pattern) + start := time.Now() + resultsChan := wrms.Player.Search(pattern) + results := []Song{} + + for result := range resultsChan { + results = append(results, result...) + } + + llog.Debug("searching for %s took %v", pattern, time.Since(start)) + data, err := json.Marshal(Event{"search", results}) if err != nil { llog.Error("Encoding the search result failed with %s", err) -- cgit v1.2.3