From c7966b3b92e50b842850cda39050ef836e703354 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 8 Dec 2021 20:59:38 +0000 Subject: [PATCH] Make sync-database refresh folders and tables properly. --- server/scripts/sync-database/sync-database.ts | 74 +------------------ 1 file changed, 4 insertions(+), 70 deletions(-) diff --git a/server/scripts/sync-database/sync-database.ts b/server/scripts/sync-database/sync-database.ts index 37154a4c2..26e2d0afc 100644 --- a/server/scripts/sync-database/sync-database.ts +++ b/server/scripts/sync-database/sync-database.ts @@ -157,83 +157,17 @@ const syncInstructions: SyncInstructions[] = [ collection: ICollection, logger ) => { - const bwriteOps: BulkWriteOperation[] = []; + const r = await GenericUpsert(folders, collection, "folderID", logger, true); - for (const folder of folders) { - if (!TachiConfig.GAMES.includes(folder.game)) { - continue; // Skip things for games we don't care about. - } - - const exists = await collection.findOne({ - folderID: folder.folderID, - }); - - if (!exists) { - bwriteOps.push({ - // @ts-expect-error faulty monk types - insertOne: { document: folder }, - }); - } else if (fjsh.hash(folder, "sha256") !== fjsh.hash(exists, "sha256")) { - bwriteOps.push({ - updateOne: { - filter: { - folderID: folder.folderID, - }, - update: { - $set: folder, - }, - }, - }); - } - } - - if (bwriteOps.length) { - await collection.bulkWrite(bwriteOps); + if (r) { await InitaliseFolderChartLookup(); } }, }, { pattern: /^tables$/u, - handler: async ( - tables: TableDocument[], - collection: ICollection, - logger - ) => { - const bwriteOps: BulkWriteOperation[] = []; - - for (const table of tables) { - if (!TachiConfig.GAMES.includes(table.game)) { - continue; // Skip things for games we don't care about. - } - - const exists = await collection.findOne({ - tableID: table.tableID, - }); - - if (!exists) { - bwriteOps.push({ - // @ts-expect-error faulty monk types - insertOne: { document: table }, - }); - } else if (fjsh.hash(table, "sha256") !== fjsh.hash(exists, "sha256")) { - bwriteOps.push({ - updateOne: { - filter: { - tableID: table.tableID, - }, - update: { - $set: table, - }, - }, - }); - } - } - - if (bwriteOps.length) { - await collection.bulkWrite(bwriteOps); - } - }, + handler: (tables: TableDocument[], collection: ICollection, logger) => + GenericUpsert(tables, collection, "tableID", logger, true), }, { pattern: /^bms-course-lookup$/u,