diff --git a/backend/explore/explore.go b/backend/explore/explore.go index c9f0f73..aa76c5b 100644 --- a/backend/explore/explore.go +++ b/backend/explore/explore.go @@ -11,8 +11,6 @@ import ( "sync" "time" - "github.com/wailsapp/wails/v2/pkg/runtime" - "yellowjacket/backend/database" ) @@ -162,20 +160,29 @@ func (e *Service) SearchLocal(query string) *MBSearchResult { // serialization queue, ensuring sub-millisecond response times. func (e *Service) SearchLocalHandler() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + defer func() { + if rv := recover(); rv != nil { + e.logger.Error("search-local handler panic", "recover", rv) + http.Error(w, "internal error", http.StatusInternalServerError) + } + }() + query := r.URL.Query().Get("q") if query == "" { - w.WriteHeader(http.StatusBadRequest) - return - } - - result := e.SearchLocal(query) - if result == nil { w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte("null")) return } + result := e.SearchLocal(query) + w.Header().Set("Content-Type", "application/json") + + if result == nil { + _, _ = w.Write([]byte("null")) + return + } + _ = json.NewEncoder(w).Encode(result) }) } @@ -363,40 +370,6 @@ func (e *Service) Search(query string) (*MBSearchResult, error) { "elapsed", p0Dur.Round(time.Millisecond), ) - // Emit local results immediately via event so the frontend can - // render them while the full pipeline runs. This avoids the - // Wails RPC serialization bottleneck that blocks SearchLocal. - if len(indexHits) > 0 { - var localResult MBSearchResult - mergeIndexHits(&localResult, indexHits) - - // Remove SPAs from local results. - if len(localResult.Artists) > 0 { - filtered := localResult.Artists[:0] - for _, a := range localResult.Artists { - if !mbSpecialPurposeArtists[a.MBID] { - filtered = append(filtered, a) - } - } - - localResult.Artists = filtered - } - - if len(localResult.Artists) > maxResults { - localResult.Artists = localResult.Artists[:maxResults] - } - - if len(localResult.ReleaseGroups) > maxResults { - localResult.ReleaseGroups = localResult.ReleaseGroups[:maxResults] - } - - if len(localResult.Recordings) > maxResults { - localResult.Recordings = localResult.Recordings[:maxResults] - } - - runtime.EventsEmit(e.ctx, "search:local-results", localResult) - } - // Phase 1: concurrent MB search (3 goroutines) with a deadline // so a slow MusicBrainz server doesn't hold up the whole search. p1Start := time.Now() diff --git a/frontend/wailsjs/go/explore/Service.d.ts b/frontend/wailsjs/go/explore/Service.d.ts index d73cc78..aa034a9 100755 --- a/frontend/wailsjs/go/explore/Service.d.ts +++ b/frontend/wailsjs/go/explore/Service.d.ts @@ -1,6 +1,7 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT import {explore} from '../models'; +import {http} from '../models'; import {context} from '../models'; export function BrowseReleaseGroups(arg1:string):Promise>; @@ -37,6 +38,8 @@ export function SearchArtists(arg1:string):Promise>; export function SearchLocal(arg1:string):Promise; +export function SearchLocalHandler():Promise; + export function SearchRecordings(arg1:string):Promise>; export function SearchReleaseGroups(arg1:string):Promise>; diff --git a/frontend/wailsjs/go/explore/Service.js b/frontend/wailsjs/go/explore/Service.js index bd9b699..d92f32c 100755 --- a/frontend/wailsjs/go/explore/Service.js +++ b/frontend/wailsjs/go/explore/Service.js @@ -70,6 +70,10 @@ export function SearchLocal(arg1) { return window['go']['explore']['Service']['SearchLocal'](arg1); } +export function SearchLocalHandler() { + return window['go']['explore']['Service']['SearchLocalHandler'](); +} + export function SearchRecordings(arg1) { return window['go']['explore']['Service']['SearchRecordings'](arg1); }