fix: instant search via frontend library cache — no Go calls at all
The HTTP endpoint approach still crashed due to Wails asset server issues. Replaced with a pure frontend solution: searchLibraryCache() does a substring match against the libraryStore's cached artists and albums arrays. This is pure JS — zero Go calls, zero RPC, zero network — guaranteed instant. Results appear immediately as the user types. The full MB+LB search pipeline still runs via Wails RPC and replaces the library matches with richer results when done. Added cachedArtists/cachedAlbums getters to LibraryStore for synchronous read-only access to the already-loaded data. Removed the /api/search-local HTTP handler from the backend.
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"math"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -155,38 +154,6 @@ func (e *Service) SearchLocal(query string) *MBSearchResult {
|
||||
return &result
|
||||
}
|
||||
|
||||
// SearchLocalHandler returns an http.Handler that serves local
|
||||
// index search results as JSON. This bypasses the Wails RPC
|
||||
// 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.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)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MusicBrainz lookup
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user