From 2dc68139f718bf6f071c8dbc152ffb023de66567 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Mon, 27 Jun 2022 00:08:41 -0400 Subject: [PATCH] Streaming-only subs are now actually paused DB transfers in any direction now generate backups and associated logs are set to info --- backend/app.js | 9 +++++---- backend/db.js | 7 ++++--- backend/subscriptions.js | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/app.js b/backend/app.js index 7222baf..1cbb943 100644 --- a/backend/app.js +++ b/backend/app.js @@ -571,14 +571,15 @@ function calculateSubcriptionRetrievalDelay(subscriptions_amount) { } async function watchSubscriptions() { - // auto pause deprecated streamingOnly mode - await db_api.updateRecords('subscriptions', {streamingOnly: true}, {paused: true}); - let subscriptions = await subscriptions_api.getAllSubscriptions(); if (!subscriptions) return; - const valid_subscriptions = subscriptions.filter(sub => !sub.paused); + // auto pause deprecated streamingOnly mode + const streaming_only_subs = subscriptions.filter(sub => sub.streamingOnly); + subscriptions_api.updateSubscriptionPropertyMultiple(streaming_only_subs, {paused: true}); + + const valid_subscriptions = subscriptions.filter(sub => !sub.paused && !sub.streamingOnly); let subscriptions_amount = valid_subscriptions.length; let delay_interval = calculateSubcriptionRetrievalDelay(subscriptions_amount); diff --git a/backend/db.js b/backend/db.js index 99d781d..f597dff 100644 --- a/backend/db.js +++ b/backend/db.js @@ -985,7 +985,7 @@ exports.backupDB = async () => { const backup_file_name = `${using_local_db ? 'local' : 'remote'}_db.json.${Date.now()/1000}.bak`; const path_to_backups = path.join(backup_dir, backup_file_name); - logger.verbose(`Backing up ${using_local_db ? 'local' : 'remote'} DB to ${path_to_backups}`); + logger.info(`Backing up ${using_local_db ? 'local' : 'remote'} DB to ${path_to_backups}`); const table_to_records = {}; for (let i = 0; i < tables_list.length; i++) { @@ -1032,10 +1032,11 @@ exports.transferDB = async (local_to_remote) => { table_to_records[table] = await exports.getRecords(table); } + logger.info('Backup up DB...'); + await exports.backupDB(); // should backup always + using_local_db = !local_to_remote; if (local_to_remote) { - logger.debug('Backup up DB...'); - await exports.backupDB(); const db_connected = await exports.connectToDB(5, true); if (!db_connected) { logger.error('Failed to transfer database - could not connect to MongoDB. Verify that your connection URL is valid.'); diff --git a/backend/subscriptions.js b/backend/subscriptions.js index 6e9e454..9178804 100644 --- a/backend/subscriptions.js +++ b/backend/subscriptions.js @@ -458,7 +458,7 @@ async function updateSubscription(sub) { async function updateSubscriptionPropertyMultiple(subs, assignment_obj) { subs.forEach(async sub => { - await updateSubscriptionProperty(sub, assignment_obj, sub.user_uid); + await updateSubscriptionProperty(sub, assignment_obj); }); }