Search: clear the previous result line while a new search loads, draw long lists in chunks, append the full list instead of redrawing, warm fewer thumbnails
This commit is contained in:
@@ -1894,7 +1894,9 @@ function startCacheResyncWatch() {
|
||||
// Pull a result set's artwork into the service worker's thumbnail cache, a few at
|
||||
// a time, so a saved search still has pictures offline.
|
||||
function warmSearchThumbs(results) {
|
||||
const urls = (results || []).map((r) => r && r.thumbnail).filter(Boolean).slice(0, 100);
|
||||
// Only the first screens: warming 100+ images competes with the results
|
||||
// themselves on a slow link.
|
||||
const urls = (results || []).map((r) => r && r.thumbnail).filter(Boolean).slice(0, 24);
|
||||
let i = 0;
|
||||
const next = () => { if (i >= urls.length) return; warmThumb(urls[i++]); setTimeout(next, 40); };
|
||||
next(); next(); next();
|
||||
@@ -8067,6 +8069,9 @@ function wireUI() {
|
||||
collectSearchMetadata(q, instant.results);
|
||||
if (SearchLibrary.isFresh(instant.ts)) { scrollListIntoViewPortrait(); return; }
|
||||
} else {
|
||||
// Never leave the previous search's "Updated … · N results" line over
|
||||
// an empty list while this one loads.
|
||||
$('searchMeta')?.classList.add('hidden');
|
||||
render();
|
||||
showSearchSkeletons();
|
||||
}
|
||||
@@ -8120,8 +8125,15 @@ function wireUI() {
|
||||
const more = await API.search(q);
|
||||
const full = merged(more?.results || []);
|
||||
if (mySeq !== searchSeq || !more?.ok || full.length <= results.length) return;
|
||||
searchResults = full;
|
||||
renderList();
|
||||
const shown = searchResults;
|
||||
const prefix = shown.length <= full.length && shown.every((v, i) => full[i] && full[i].id === v.id);
|
||||
if (prefix && els.cards.children.length) {
|
||||
// Grow the same array, so cards already drawn queue the full list too.
|
||||
const from = shown.length;
|
||||
shown.push(...full.slice(from));
|
||||
searchResults = shown;
|
||||
appendListCards(shown, from);
|
||||
} else { searchResults = full; renderList(); }
|
||||
RecentSearches.cacheResults(q, full, Date.now());
|
||||
showSearchMeta(q, Date.now());
|
||||
} catch { /* keep the first page */ }
|
||||
|
||||
Reference in New Issue
Block a user