Update Scan to use the new communication method (request data from database service)

This commit is contained in:
omaroughriss 2025-11-27 16:40:02 +01:00
parent 29d2688278
commit 92a9c6e455

View File

@ -70,33 +70,58 @@ async function requestFromMainThread(client, action, payload) {
// SCAN LOGIC // SCAN LOGIC
// ============================================ // ============================================
async function scanMissingData(processesToScan) { async function scanMissingData(processesToScan, client) {
console.log('Scanning for missing data...'); console.log('[Service Worker] Scanning for missing data...');
const myProcesses = await getProcesses(processesToScan);
const myProcesses = await requestFromMainThread(client, 'GET_MULTIPLE_OBJECTS', {
storeName: 'processes',
keys: processesToScan
});
let toDownload = new Set(); let toDownload = new Set();
// Iterate on each process let diffsToCreate = [];
if (myProcesses && myProcesses.length != 0) { if (myProcesses && myProcesses.length != 0) {
for (const process of myProcesses) { for (const process of myProcesses) {
// Iterate on states
const firstState = process.states[0]; const firstState = process.states[0];
const processId = firstState.commited_in; const processId = firstState.commited_in;
for (const state of process.states) { for (const state of process.states) {
if (state.state_id === EMPTY32BYTES) continue; if (state.state_id === EMPTY32BYTES) continue;
// iterate on pcd_commitment
for (const [field, hash] of Object.entries(state.pcd_commitment)) { for (const [field, hash] of Object.entries(state.pcd_commitment)) {
// Skip public fields
if (state.public_data[field] !== undefined || field === 'roles') continue; 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) { if (!existingData) {
toDownload.add(hash); 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 { } else {
// We remove it if we have it in the set
if (toDownload.delete(hash)) { if (toDownload.delete(hash)) {
console.log(`Removing ${hash} from the set`); console.log(`[Service Worker] Removing ${hash} from the set`);
} }
} }
} }