From 242bbcd5971080c65fbbe6f502a72f7f124cd2c3 Mon Sep 17 00:00:00 2001 From: Kerboul Date: Thu, 3 Apr 2025 09:07:45 +0200 Subject: [PATCH] =?UTF-8?q?Renommer=20la=20fonction=20de=20connexion=20?= =?UTF-8?q?=C3=A0=20la=20base=20de=20donn=C3=A9es=20et=20am=C3=A9liorer=20?= =?UTF-8?q?la=20gestion=20des=20erreurs.=20Nettoyer=20le=20code=20en=20sup?= =?UTF-8?q?primant=20les=20commentaires=20inutiles=20et=20r=C3=A9initialis?= =?UTF-8?q?er=20le=20compteur=20apr=C3=A8s=20la=20journalisation=20des=20m?= =?UTF-8?q?odifications.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.js | 6 +++--- src/data/filewatcher.js | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/db.js b/db.js index 037e842..10b2f75 100644 --- a/db.js +++ b/db.js @@ -8,16 +8,16 @@ const client = new Client({ database: 'timelapse' }); -function connectWithRetry() { +function init_database() { client.connect(err => { if (err) { console.error('Erreur de connexion à la base de données:', err); - setTimeout(connectWithRetry, 30000); + setTimeout(init_database, 30000); } else { console.log('[DB] Connecté à la base de données PostgreSQL.'); } }); } -connectWithRetry(); +init_database(); module.exports = client; \ No newline at end of file diff --git a/src/data/filewatcher.js b/src/data/filewatcher.js index 8e8ed4c..0cd653a 100644 --- a/src/data/filewatcher.js +++ b/src/data/filewatcher.js @@ -16,9 +16,7 @@ async function checkAndRemoveInvalidEntries() { } } - // Scan all images in storage const allImages = await storageManager.scanAllImages(); - //console.log('Scanned all images:', allImages); for (const imagePath of allImages) { const entryRes = await db.query('SELECT id FROM measurements WHERE path = $1', [imagePath]); if (entryRes.rows.length === 0) { @@ -29,6 +27,7 @@ async function checkAndRemoveInvalidEntries() { } if (localCounter > 0) { console.log(`[INFO] ${localCounter} entrées ont été modifiées`); + localCounter = 0; // Reset the counter after logging } } catch (err) { console.error('Error checking and removing invalid entries:', err);