diff --git a/js/ui.js b/js/ui.js index 5de576b4..7c341cc5 100644 --- a/js/ui.js +++ b/js/ui.js @@ -163,7 +163,7 @@ function resetResults(clearSummary, clearPagination) { if (clearSummary) summaryTable.innerText = ''; clearPagination && pagination.forEach(item => item.classList.add('d-none')); const resultTable = document.getElementById('resultTableBody'); - resultTable.innerHTML = ''; + resultsBuffer = resultTable.cloneNode(false) predictions = {}; seenTheDarkness = false; shownDaylightBanner = false; @@ -1511,6 +1511,9 @@ const setUpWorkerMessaging = () => { } break; case 'hide-spinner': + const table = document.getElementById('resultTableBody') + table.replaceWith(resultsBuffer); + document.getElementById('resultsDiv').scrollTo({ top: 0, left: 0, behavior: "smooth" }); hideLoadingSpinner(); break; case 'location-list': @@ -2635,7 +2638,7 @@ async function onPredictionDone({ if (resultsBuffer) { const results = document.getElementById('resultTableBody'); results.replaceWith(resultsBuffer); - resultsBuffer = undefined; + // resultsBuffer = undefined; } updateSummary({ summary: summary, filterSpecies: filterSpecies }); @@ -2874,7 +2877,7 @@ async function renderResult({ } -let resultsBuffer, detectionsModal; +let resultsBuffer = document.getElementById('resultTableBody').cloneNode(false), detectionsModal; const detectionsModalDiv = document.getElementById('detectionsModal') detectionsModalDiv.addEventListener('hide.bs.modal', (e) => { @@ -2886,11 +2889,11 @@ const updateResultTable = (row, isFromDB, isSelection) => { const table = isSelection ? document.getElementById('selectionResultTableBody') : document.getElementById('resultTableBody'); if (isFromDB && !isSelection) { - if (!resultsBuffer) resultsBuffer = table.cloneNode(); + //if (!resultsBuffer) resultsBuffer = table.cloneNode(); resultsBuffer.lastElementChild ? resultsBuffer.lastElementChild.insertAdjacentHTML('afterend', row) : resultsBuffer.innerHTML = row; - table.replaceWith(resultsBuffer); + } else { if (isSelection) { if (!detectionsModal || !detectionsModal._isShown) { @@ -3139,6 +3142,7 @@ const changeNocmigMode = () => { }); updatePrefs(); worker.postMessage({ action: 'update-state', globalOffset: 0, filteredOffset: {}}); + resetResults(true, true); worker.postMessage({ action: 'filter', species: isSpeciesViewFiltered(true), diff --git a/js/worker.js b/js/worker.js index 370a1263..365786c9 100644 --- a/js/worker.js +++ b/js/worker.js @@ -20,7 +20,7 @@ let workerInstance = 0; let TEMP, appPath, CACHE_LOCATION, BATCH_SIZE, LABELS, BACKEND, batchChunksToSend = {}; let SEEN_LIST_UPDATE = false // Prevents list updates from every worker on every change -const DEBUG = false; +const DEBUG = true; const DATASET = true; const adding_chirpity_additions = true; @@ -79,9 +79,9 @@ const createDB = async (file) => { UNIQUE (day, fileID), CONSTRAINT fk_files FOREIGN KEY (fileID) REFERENCES files(id) ON DELETE CASCADE)`); - // await db.runAsync('CREATE INDEX idx_datetime ON records(dateTime)'); - // await db.runAsync('CREATE INDEX idx_species ON records(speciesID)'); - // await db.runAsync('CREATE INDEX idx_files ON records(fileID)'); + await db.runAsync('CREATE INDEX idx_datetime ON records(dateTime)'); + await db.runAsync('CREATE INDEX idx_species ON records(speciesID)'); + await db.runAsync('CREATE INDEX idx_files ON records(fileID)'); if (archiveMode) { for (let i = 0; i < LABELS.length; i++) { const [sname, cname] = LABELS[i].replaceAll("'", "''").split('_'); @@ -132,7 +132,7 @@ async function loadDB(path) { console.log('Added isDaylight column to records table') } // const datetime = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_datetime ON records (dateTime)'); - // const covering_total = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_covering_total ON records (confidence, isDaylight)'); + const covering_total = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_covering_total ON records (confidence, isDaylight)'); // const species = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_species ON records (speciesID)'); //await Promise.all([datetime, species, files, covering_total]); console.log("Opened and cleaned disk db " + file) @@ -270,12 +270,12 @@ async function handleMessage(e) { t0 = Date.now() UI.postMessage({event: 'show-spinner'}); await getResults(args); - args.updateSummary && await getSummary(args); const t1 = Date.now() + args.updateSummary && await getSummary(args); + const t2 = Date.now() await getTotal(args); //await Promise.all([getResults(args), getSummary(args)]); - console.log('Filter took ', (Date.now() - t0) / 1000, 'seconds', '\nGettotal took ', (Date.now() - t1) / 1000, 'seconds',) - + console.log('Filter took ', (Date.now() - t0) / 1000, 'seconds', '\nGetTotal took ', (Date.now() - t2) / 1000, 'seconds', '\nGetSummary took ', (t2 - t1) / 1000, 'seconds') } break; case 'get-detected-species-list': @@ -437,7 +437,6 @@ const getSummaryParams = (species) => { extraParams.push(...blocked); STATE.locationID && extraParams.push(STATE.locationID); params.push(...extraParams); - species && params.push(species); return params } @@ -477,9 +476,7 @@ const prepSummaryStatement = (species) => { SELECT cname, sname, COUNT(*) as count, SUM(callcount) as calls, ROUND(MAX(ranked_records.confidence) / 10.0, 0) as max FROM ranked_records WHERE ranked_records.rank <= ${STATE.topRankin} - GROUP BY speciesID`; - if (species) summaryStatement += ` WHERE cname = ? `; - summaryStatement += ' ORDER BY cname'; + GROUP BY speciesID ORDER BY cname`; STATE.GET_SUMMARY_SQL = STATE.db.prepare(summaryStatement); //console.log('Summary SQL statement:\n' + summaryStatement) } @@ -2143,8 +2140,6 @@ const getResults = async ({ let index = offset; AUDACITY = {}; - let t0 = Date.now(); - const params = getResultsParams(species, confidence, offset, limit, topRankin); prepResultsStatement(species, limit === Infinity); @@ -2186,7 +2181,6 @@ const getResults = async ({ sendResult(++index, r, true) } } - console.log("Get Results took", (Date.now() - t0) / 1000, " seconds"); if (!result.length) { if (STATE.selection) { // No more detections in the selection