From 92a9c6e45520ecbca87d9ac75e78578a49a8bfee Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Thu, 27 Nov 2025 16:40:02 +0100 Subject: [PATCH] Update Scan to use the new communication method (request data from database service) --- public/database.worker.js | 51 +++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/public/database.worker.js b/public/database.worker.js index a24731d..4fcef70 100755 --- a/public/database.worker.js +++ b/public/database.worker.js @@ -70,33 +70,58 @@ async function requestFromMainThread(client, action, payload) { // SCAN LOGIC // ============================================ -async function scanMissingData(processesToScan) { - console.log('Scanning for missing data...'); - const myProcesses = await getProcesses(processesToScan); +async function scanMissingData(processesToScan, client) { + console.log('[Service Worker] Scanning for missing data...'); + + const myProcesses = await requestFromMainThread(client, 'GET_MULTIPLE_OBJECTS', { + storeName: 'processes', + keys: processesToScan + }); let toDownload = new Set(); - // Iterate on each process + let diffsToCreate = []; + if (myProcesses && myProcesses.length != 0) { for (const process of myProcesses) { - // Iterate on states const firstState = process.states[0]; const processId = firstState.commited_in; for (const state of process.states) { if (state.state_id === EMPTY32BYTES) continue; - // iterate on pcd_commitment + for (const [field, hash] of Object.entries(state.pcd_commitment)) { - // Skip public fields if (state.public_data[field] !== undefined || field === 'roles') continue; - // Check if we have the data in db - const existingData = await getBlob(hash); + + const existingData = await requestFromMainThread(client, 'GET_OBJECT', { + storeName: 'data', + key: hash + }); + if (!existingData) { toDownload.add(hash); - // We also add an entry in diff, in case it doesn't already exist - await addDiff(processId, state.state_id, hash, state.roles, field); + + const existingDiff = await requestFromMainThread(client, 'GET_OBJECT', { + storeName: 'diffs', + key: hash + }); + + if (!existingDiff) { + diffsToCreate.push({ + process_id: processId, + state_id: state.state_id, + value_commitment: hash, + roles: state.roles, + field: field, + description: null, + previous_value: null, + new_value: null, + notify_user: false, + need_validation: false, + validation_status: 'None' + }); + } } else { - // We remove it if we have it in the set if (toDownload.delete(hash)) { - console.log(`Removing ${hash} from the set`); + console.log(`[Service Worker] Removing ${hash} from the set`); } } }