feat(library): browse local index race and catalog paths (#847)

* feat(library): race local index vs network on browse text search

Wire Artists, Composers, Tracks, and SearchResults to parallel local FTS
and network search3 with graceful fallback when remote fails while the
index is ready.

* feat(library): local browse for albums/artists and dev race logging

Serve All Albums and Artists catalog from the local index when ready,
with network fallback. Log browse text-search race outcomes to DevTools
(`[psysonic][library] browse-race …`) including winner, timings, and hits.

* docs(changelog): note PR #847 browse local index race and catalog paths

* refactor(library): unify DevTools search log format

Live Search, Advanced Search, and browse races emit one-line
`search [surface] …` entries via formatLibrarySearchLine (DEV only).
This commit is contained in:
cucadmuh
2026-05-22 02:44:25 +03:00
committed by GitHub
parent bd742c958c
commit 7afddf7b84
16 changed files with 904 additions and 73 deletions
+38 -13
View File
@@ -26,8 +26,14 @@ import { useMainstageInpageHeaderTight } from '../hooks/useMainstageInpageHeader
import { VirtualCardGrid } from '../components/VirtualCardGrid';
import OverlayScrollArea from '../components/OverlayScrollArea';
import { ALBUMS_INPAGE_SCROLL_VIEWPORT_ID } from '../constants/appScroll';
import { useLibraryIndexStore } from '../store/libraryIndexStore';
import {
runLocalAlbumBrowsePage,
runLocalAlbumsByGenres,
type AlbumBrowseSort,
} from '../utils/library/browseTextSearch';
type SortType = 'alphabeticalByName' | 'alphabeticalByArtist';
type SortType = AlbumBrowseSort;
type CompFilter = 'all' | 'only' | 'hide';
const PAGE_SIZE = 30;
@@ -47,6 +53,7 @@ export default function Albums() {
const musicLibraryFilterVersion = useAuthStore(s => s.musicLibraryFilterVersion);
const auth = useAuthStore();
const serverId = useAuthStore(s => s.activeServerId ?? '');
const indexEnabled = useLibraryIndexStore(s => s.isIndexEnabled(serverId));
const downloadAlbum = useOfflineStore(s => s.downloadAlbum);
const requestDownloadFolder = useDownloadModalStore(s => s.requestFolder);
@@ -183,32 +190,50 @@ export default function Albums() {
) => {
setLoading(true);
try {
const extra = yearFilter ? { fromYear: yearFilter.from, toYear: yearFilter.to } : {};
const type = yearFilter ? 'byYear' : sortType;
const data = await getAlbumList(type, PAGE_SIZE, offset, extra);
let data: SubsonicAlbum[] | null = null;
if (indexEnabled && serverId) {
data = await runLocalAlbumBrowsePage(
serverId,
sortType,
offset,
PAGE_SIZE,
yearFilter,
);
}
if (data == null) {
const extra = yearFilter ? { fromYear: yearFilter.from, toYear: yearFilter.to } : {};
const type = yearFilter ? 'byYear' : sortType;
data = await getAlbumList(type, PAGE_SIZE, offset, extra);
}
if (append) setAlbums(prev => [...prev, ...data]);
else setAlbums(data);
setHasMore(data.length === PAGE_SIZE);
} finally {
setLoading(false);
}
}, [musicLibraryFilterVersion]);
}, [musicLibraryFilterVersion, indexEnabled, serverId]);
const loadFiltered = useCallback(async (genres: string[], sortType: SortType) => {
setLoading(true);
try {
const data = await fetchByGenres(genres);
const sorted = [...data].sort((a, b) =>
sortType === 'alphabeticalByArtist'
? a.artist.localeCompare(b.artist)
: a.name.localeCompare(b.name)
);
setAlbums(sorted);
let data: SubsonicAlbum[] | null = null;
if (indexEnabled && serverId) {
data = await runLocalAlbumsByGenres(serverId, genres, sortType);
}
if (data == null) {
data = await fetchByGenres(genres);
data = [...data].sort((a, b) =>
sortType === 'alphabeticalByArtist'
? a.artist.localeCompare(b.artist)
: a.name.localeCompare(b.name),
);
}
setAlbums(data);
setHasMore(false);
} finally {
setLoading(false);
}
}, [musicLibraryFilterVersion]);
}, [musicLibraryFilterVersion, indexEnabled, serverId]);
useEffect(() => {
setPage(0);