From ea27a0d6f8453e424faac8e3921c468f4c56a3ed Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Sat, 28 Feb 2026 09:28:13 +0100 Subject: [PATCH] patch_detector: refactor --- patch_detector/index.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/patch_detector/index.ts b/patch_detector/index.ts index 2c5c950..2d0a0c3 100644 --- a/patch_detector/index.ts +++ b/patch_detector/index.ts @@ -33,21 +33,19 @@ const CDRAGON_ASSETS = [ main() async function main() { + const client = await connectToDatabase() + const dbPatch = await getLatestPatchFromDatabase(client) + // In dev mode, get patch from database (the one we have match data for) if (process.env.NODE_ENV === 'development') { console.log('Development mode: downloading cache for database patch') - const client = await connectToDatabase() - const dbPatch = await getLatestPatchFromDatabase(client) await client.close() if (dbPatch) { console.log('Latest patch in database: ' + dbPatch) await downloadAssets(dbPatch) } else { - console.log('No patch found in database, fetching latest from game...') - const latestPatch = await fetchLatestPatch() - console.log('Latest game patch: ' + latestPatch) - await downloadAssets(latestPatch) + console.log('No patch found in database!') } return } @@ -55,12 +53,12 @@ async function main() { // Production mode: check database and update if new patch const newPatch = await fetchLatestPatch() console.log('Latest patch is: ' + newPatch) - - const client = await connectToDatabase() const newDate = new Date() + if (!(await compareLatestSavedPatch(client, newPatch, newDate))) { await downloadAssets(newPatch) } + await client.close() }