From aac5e90b00dcacd11a9008fd63ecd4967b6b4d30 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Mon, 9 Dec 2024 08:45:41 -0500 Subject: [PATCH] better debug logs for library sync --- .../src/server/mqttUpdater/index.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/playnite-web/src/server/mqttUpdater/index.ts b/apps/playnite-web/src/server/mqttUpdater/index.ts index ad8e33e8..89c08d13 100755 --- a/apps/playnite-web/src/server/mqttUpdater/index.ts +++ b/apps/playnite-web/src/server/mqttUpdater/index.ts @@ -6,6 +6,8 @@ import { IDeleteQuery, IQuery, IUpdateQuery } from '../data/types.api.js' import { PubSubChannels } from '../graphql/subscriptionPublisher.js' import handlers from './handlers/index.js' +const debug = createDebugger('playnite-web/game-db-updater/index') + type HandlerOptions = { assetSaveDirectoryPath: string pubsub: PubSub @@ -16,21 +18,36 @@ type HandlerOptions = { } const batchTopic = /^playnite\/[^/]+\/batch$/ +const librarySync = /^playnite\/[^/]+\/library\/sync\/(.*)$/ const mqttUpdater = async (options: HandlerOptions): Promise => { - const debug = createDebugger('playnite-web/game-db-updater/index') debug('Starting game-db-updater') options.mqtt.subscribe('playnite/#') await fs.mkdir(options.assetSaveDirectoryPath, { recursive: true }) + let syncMessageCount = 0 options.mqtt.on('message', async (topic, payload) => { + const librarySyncMessageMatches = librarySync.exec(topic) + if (librarySyncMessageMatches?.[1] === 'start') { + syncMessageCount = 0 + return + } + if (librarySyncMessageMatches?.[1] === 'completed') { + debug( + `Library sync completed. Processed a total of ${syncMessageCount} database entities. This number should match the number of all documents, across all collections, in your games database.`, + ) + return + } + let messages: Array<{ topic: string; payload: Buffer }> = [] if (batchTopic.test(topic)) { messages = JSON.parse(payload.toString()).messages - console.log('Batched messages received', messages.length) + syncMessageCount += messages.length + debug('Batched messages received', messages.length) } else { + syncMessageCount += 1 messages.push({ topic, payload }) }