refactor(data.worker): streamline logging and comments in scanMissingData function for improved clarity and resource management

This commit is contained in:
NicolasCantu 2025-12-03 10:06:52 +01:00
parent 81025dca42
commit 77019896e5

View File

@ -78,8 +78,6 @@ function getMultipleObjects(db, storeName, keys) {
// ============================================
async function scanMissingData(processesToScan) {
console.log("[Service Worker] 🚀 Scanning with DIRECT DB ACCESS...");
let db;
try {
db = await openDB();
@ -103,7 +101,6 @@ async function scanMissingData(processesToScan) {
if (!process || !process.states) continue;
const firstState = process.states[0];
// Sécurisation : on vérifie que firstState existe
if (!firstState) continue;
const processId = firstState.commited_in;
@ -112,7 +109,6 @@ async function scanMissingData(processesToScan) {
if (state.state_id === EMPTY32BYTES) continue;
for (const [field, hash] of Object.entries(state.pcd_commitment)) {
// On ignore les données publiques ou les rôles
if (
(state.public_data && state.public_data[field] !== undefined) ||
field === "roles"
@ -144,7 +140,6 @@ async function scanMissingData(processesToScan) {
});
}
} else {
// Si on a trouvé la donnée, on est sûr de ne pas avoir besoin de la télécharger
if (toDownload.has(hash)) {
toDownload.delete(hash);
}
@ -154,13 +149,17 @@ async function scanMissingData(processesToScan) {
}
}
// On ferme la connexion BDD pour libérer les ressources
// On ferme la connexion BDD
db.close();
console.log("[Service Worker] Scan complete:", {
toDownload: toDownload.size,
diffsToCreate: diffsToCreate.length,
});
// ✅ LOG PERTINENT UNIQUEMENT : On n'affiche que si on a trouvé quelque chose
if (toDownload.size > 0 || diffsToCreate.length > 0) {
console.log("[Service Worker] 🔄 Scan found items:", {
toDownload: toDownload.size,
diffsToCreate: diffsToCreate.length,
});
}
return {
toDownload: Array.from(toDownload),
diffsToCreate: diffsToCreate,