fix: use Wails event for instant local search results
The SearchLocal RPC approach couldn't render results instantly because Wails v2 serializes Go method calls — SearchLocal would queue behind other in-flight calls. Now Search() emits a 'search:local-results' Wails event at the start of Phase 0 (before the slow MB/LB pipeline begins). The frontend listens for this event in connectedCallback and renders the local hits immediately. The event bypasses the RPC queue since it's pushed from Go, not pulled by JS. Removed the SearchLocal RPC call from the frontend entirely.
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
|
||||
"yellowjacket/backend/database"
|
||||
)
|
||||
|
||||
@@ -337,6 +339,40 @@ 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()
|
||||
|
||||
Reference in New Issue
Block a user