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) { async function scanMissingData(processesToScan) {
console.log("[Service Worker] 🚀 Scanning with DIRECT DB ACCESS...");
let db; let db;
try { try {
db = await openDB(); db = await openDB();
@ -103,7 +101,6 @@ async function scanMissingData(processesToScan) {
if (!process || !process.states) continue; if (!process || !process.states) continue;
const firstState = process.states[0]; const firstState = process.states[0];
// Sécurisation : on vérifie que firstState existe
if (!firstState) continue; if (!firstState) continue;
const processId = firstState.commited_in; const processId = firstState.commited_in;
@ -112,7 +109,6 @@ async function scanMissingData(processesToScan) {
if (state.state_id === EMPTY32BYTES) continue; if (state.state_id === EMPTY32BYTES) continue;
for (const [field, hash] of Object.entries(state.pcd_commitment)) { for (const [field, hash] of Object.entries(state.pcd_commitment)) {
// On ignore les données publiques ou les rôles
if ( if (
(state.public_data && state.public_data[field] !== undefined) || (state.public_data && state.public_data[field] !== undefined) ||
field === "roles" field === "roles"
@ -144,7 +140,6 @@ async function scanMissingData(processesToScan) {
}); });
} }
} else { } 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)) { if (toDownload.has(hash)) {
toDownload.delete(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(); db.close();
console.log("[Service Worker] Scan complete:", { // ✅ LOG PERTINENT UNIQUEMENT : On n'affiche que si on a trouvé quelque chose
toDownload: toDownload.size, if (toDownload.size > 0 || diffsToCreate.length > 0) {
diffsToCreate: diffsToCreate.length, console.log("[Service Worker] 🔄 Scan found items:", {
}); toDownload: toDownload.size,
diffsToCreate: diffsToCreate.length,
});
}
return { return {
toDownload: Array.from(toDownload), toDownload: Array.from(toDownload),
diffsToCreate: diffsToCreate, diffsToCreate: diffsToCreate,