feat(search): answer search from a local index; tier downloads by lifetime
Search's instant leg read only downloaded items, so with no downloads it returned nothing and every keystroke fell through to a full Recursive=true server query. It now reads the whole synced catalog through the same availability CTE get_items uses, gated on the same include_catalog_browse flag so search and browse cannot diverge. (UR-065, DR-108) Also fixes three defects found while confirming that: - items_fts grew by a full duplicate index every catalog pass. INSERT OR REPLACE fires no AFTER DELETE trigger without recursive_triggers, so the old index row was orphaned, and a TEXT PRIMARY KEY meant the replacement took a fresh rowid and inserted a second entry. Now a real upsert, with migration 021 rebuilding existing indexes. (DR-110) - DELETE FROM items existed nowhere, so server-side deletions never propagated. Adds a post-crawl mark-and-sweep, scoped to crawled types, skipping downloaded items, and refusing to run after a partial crawl because items.parent_id cascades. (DR-110) - The index omitted MusicArtist, Playlist and People, which search groups results by. Adds them plus people_fts (migration 022). (DR-111) Re-indexing moves from a frontend startup call to a Rust background task with a 6h TTL, so a long session no longer searches a stale catalog and a restart no longer forces a crawl regardless of freshness. (DR-109, IR-030) Downloads gain a lifetime tier. Eviction selected every completed row by age with no download_source filter, so hitting the storage limit deleted the oldest download -- typically one saved deliberately for offline -- to make room for a precached track. It now reclaims only 'auto' rows, and expired ones are reclaimed first, before live cache is evicted. (DR-126, DR-127) Downloaded video and audio-only handoffs now play from disk instead of streaming; the video path had never consulted downloads at all. No transcode is involved: MPV runs video=no and ExoPlayer has no surface for an Audio item. (DR-123 in part, DR-128) FTS queries are built as quoted phrases so apostrophes, hyphens and slashes are data rather than operator syntax, and the item-type filter is bound rather than interpolated. Specs: docs/specs/catalog-index-search.md, docs/specs/read-through-media-cache.md Includes concurrently-developed favourites browsing and background-audio stream-end handling; the two workstreams share offline.rs, lib.rs and online.rs, so no subset of files builds independently.
This commit is contained in:
+55
-4
@@ -238,7 +238,7 @@ async playerPlayNextEpisode(item: PlayItemRequest) : Promise<PlayerStatus> {
|
||||
* - Frontend when audio track ends via backend event - no itemId/repositoryHandle needed
|
||||
* - Android JNI callback also triggers this logic directly
|
||||
*
|
||||
* TRACES: UR-023, UR-026, UR-040 | DR-047, DR-052
|
||||
* TRACES: UR-023, UR-026, UR-040 | DR-047, DR-052, DR-129
|
||||
*/
|
||||
async playerOnPlaybackEnded(itemId: string | null, repositoryHandle: string | null) : Promise<null> {
|
||||
return await TAURI_INVOKE("player_on_playback_ended", { itemId, repositoryHandle });
|
||||
@@ -262,6 +262,23 @@ async playerReportPosition(position: number, duration: number) : Promise<null> {
|
||||
async playerReportMediaLoaded(duration: number) : Promise<null> {
|
||||
return await TAURI_INVOKE("player_report_media_loaded", { duration });
|
||||
},
|
||||
/**
|
||||
* The on-disk path for a downloaded item, for playback surfaces that resolve
|
||||
* their own source rather than going through the queue.
|
||||
*
|
||||
* The video player is the reason this exists: audio has preferred local files
|
||||
* since queue construction, but video asks the repository for a stream URL and
|
||||
* never consults `downloads`, so a downloaded film was still streamed — costing
|
||||
* bandwidth that had already been spent and failing outright when offline.
|
||||
*
|
||||
* Returns `None` when nothing is downloaded *or* the file is missing, so the
|
||||
* caller falls back to streaming.
|
||||
*
|
||||
* TRACES: UR-071 | DR-123 | UT-116
|
||||
*/
|
||||
async playerLocalMediaPath(itemId: string) : Promise<string | null> {
|
||||
return await TAURI_INVOKE("player_local_media_path", { itemId });
|
||||
},
|
||||
/**
|
||||
* Preload upcoming tracks from the queue
|
||||
* This queues background downloads for the next N tracks that aren't already downloaded
|
||||
@@ -1422,6 +1439,20 @@ async repositoryMarkFavorite(handle: string, itemId: string) : Promise<null> {
|
||||
async repositoryUnmarkFavorite(handle: string, itemId: string) : Promise<null> {
|
||||
return await TAURI_INVOKE("repository_unmark_favorite", { handle, itemId });
|
||||
},
|
||||
/**
|
||||
* Everything the viewer has favourited, across libraries, narrowed by scope.
|
||||
*
|
||||
* Two-phase like `repository_search`: the local answer returns immediately and
|
||||
* a background server pass emits `favorites-changed` when the server's set
|
||||
* differs. Without the second phase a favourite marked in another client shows
|
||||
* up only on the *second* visit to the page, since the cache-first read hands
|
||||
* back local rows and the refresh is invisible to the frontend.
|
||||
*
|
||||
* TRACES: UR-067 | DR-115, DR-120, JA-033 | UT-107
|
||||
*/
|
||||
async repositoryGetFavorites(handle: string, scope: SearchScope, options: GetItemsOptions | null) : Promise<SearchResult> {
|
||||
return await TAURI_INVOKE("repository_get_favorites", { handle, scope, options });
|
||||
},
|
||||
/**
|
||||
* Get person details
|
||||
*/
|
||||
@@ -1704,7 +1735,15 @@ storageLimit: number;
|
||||
/**
|
||||
* Only cache on WiFi
|
||||
*/
|
||||
wifiOnly: boolean }
|
||||
wifiOnly: boolean;
|
||||
/**
|
||||
* How long a temporary (`download_source = 'auto'`) download lives before
|
||||
* it is reclaimed, in hours. 0 disables expiry, leaving space pressure as
|
||||
* the only reclaim trigger.
|
||||
*
|
||||
* TRACES: UR-071 | DR-127
|
||||
*/
|
||||
temporaryTtlHours: number }
|
||||
/**
|
||||
* Cached media item returned to frontend
|
||||
*/
|
||||
@@ -1729,7 +1768,12 @@ itemsCached: number;
|
||||
/**
|
||||
* Libraries that failed to sync (e.g. server hiccup); best-effort.
|
||||
*/
|
||||
librariesFailed: number }
|
||||
librariesFailed: number;
|
||||
/**
|
||||
* Entries removed because the server no longer has them. Always 0 when any
|
||||
* library failed, since a partial crawl cannot prove an item is gone.
|
||||
*/
|
||||
itemsPruned: number }
|
||||
export type CatalogSyncStatus = {
|
||||
/**
|
||||
* RFC-3339 timestamp of the last successful sync, if any.
|
||||
@@ -1837,7 +1881,14 @@ export type GetImageRequest = { itemId: string; imageType: string; maxWidth?: nu
|
||||
/**
|
||||
* Options for querying items
|
||||
*/
|
||||
export type GetItemsOptions = { startIndex?: number | null; limit?: number | null; sortBy?: string | null; sortOrder?: string | null; includeItemTypes?: string[] | null; recursive?: boolean | null; fields?: string[] | null; genres?: string[] | null }
|
||||
export type GetItemsOptions = { startIndex?: number | null; limit?: number | null; sortBy?: string | null; sortOrder?: string | null; includeItemTypes?: string[] | null; recursive?: boolean | null; fields?: string[] | null; genres?: string[] | null;
|
||||
/**
|
||||
* Restrict the listing to favourited items. Backs the per-library
|
||||
* favourites toggle; composes with every other filter here.
|
||||
*
|
||||
* TRACES: UR-067 | DR-116 | UT-104
|
||||
*/
|
||||
favoritesOnly?: boolean | null }
|
||||
/**
|
||||
* Image options
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user