From fec9c6556e181fc68068eae3db9e8ec81208221d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 15 May 2024 21:32:50 -0300 Subject: client: stub search index download progress --- src/static/js/search-worker.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'src/static/js/search-worker.js') diff --git a/src/static/js/search-worker.js b/src/static/js/search-worker.js index c2bdcaee..9a7827da 100644 --- a/src/static/js/search-worker.js +++ b/src/static/js/search-worker.js @@ -14,6 +14,7 @@ import { } from '../shared-util/sugar.js'; import {loadDependency} from './module-import-shims.js'; +import {fetchWithProgress} from './xhr-util.js'; // Will be loaded from dependencies. let decompress; @@ -24,7 +25,7 @@ let idb; let status = null; let indexes = null; -globalThis.onmessage = handleWindowMessage; +onmessage = handleWindowMessage; postStatus('alive'); Promise.all([ @@ -158,6 +159,8 @@ async function main() { const [indexData, idbIndexData] = await background; + delete idbIndexData.generic; + const keysNeedingFetch = (idbIndexData ? Object.keys(indexData) @@ -170,10 +173,34 @@ async function main() { Object.keys(indexData) .filter(key => !keysNeedingFetch.includes(key)) + if (!empty(keysNeedingFetch)) { + postMessage({ + kind: 'download-begun', + context: 'search-indexes', + keys: keysNeedingFetch, + }); + } + const fetchPromises = - keysNeedingFetch - .map(key => rebase(key + '.json.msgpack')) - .map(url => fetch(url)); + keysNeedingFetch.map(key => + fetchWithProgress( + rebase(key + '.json.msgpack'), + progress => { + postMessage({ + kind: 'download-progress', + context: 'search-indexes', + progress: progress / 1.00, + key, + }); + }).then(response => { + postMessage({ + kind: 'download-complete', + context: 'search-indexes', + key, + }); + + return response; + })); const fetchBlobPromises = fetchPromises @@ -316,14 +343,14 @@ async function handleWindowActionMessage(message) { function postStatus(newStatus) { status = newStatus; - globalThis.postMessage({ + postMessage({ kind: 'status', status: newStatus, }); } function postActionResult(id, status, value) { - globalThis.postMessage({ + postMessage({ kind: 'result', id, status, -- cgit 1.3.0-6-gf8a5