From 33a3fa79687bfea8e13a56f20787c026e161698c Mon Sep 17 00:00:00 2001 From: thecodrr Date: Tue, 6 Jul 2021 12:11:12 +0500 Subject: [PATCH] fix: filter out unnecessary keys when creating backups --- packages/core/database/backup.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/core/database/backup.js b/packages/core/database/backup.js index 32193d1d8..5292ee1d2 100644 --- a/packages/core/database/backup.js +++ b/packages/core/database/backup.js @@ -6,7 +6,8 @@ import { } from "../common.js"; import SparkMD5 from "spark-md5"; -const invalidKeys = ["user", "t", "lastBackupTime"]; +const invalidKeys = ["user", "t", "v", "lastBackupTime", "lastSynced"]; +const invalidIndices = ["tags", "colors"]; const validTypes = ["mobile", "web", "node"]; export default class Backup { /** @@ -34,11 +35,11 @@ export default class Backup { if (!validTypes.some((t) => t === type)) throw new Error("Invalid type. It must be one of 'mobile' or 'web'."); - const keys = (await this._db.context.getAllKeys()).filter( - (key) => !invalidKeys.some((t) => t === key) + let keys = await this._db.context.getAllKeys(); + let data = filterData( + Object.fromEntries(await this._db.context.readMulti(keys)) ); - let data = Object.fromEntries(await this._db.context.readMulti(keys)); let hash = {}; if (encrypt) { @@ -114,10 +115,6 @@ export default class Backup { ); const collections = [ - { - index: data["notes"], - dbCollection: this._db.notes, - }, { index: data["notebooks"], dbCollection: this._db.notebooks, @@ -130,6 +127,10 @@ export default class Backup { index: data["content"], dbCollection: this._db.content, }, + { + index: data["notes"], + dbCollection: this._db.notes, + }, { index: ["settings"], dbCollection: this._db.settings, @@ -161,3 +162,15 @@ export default class Backup { } } } + +function filterData(data) { + let skippedKeys = [...invalidKeys, ...invalidIndices]; + invalidIndices.forEach((key) => { + const index = data[key]; + if (!index) return; + skippedKeys.push(...index); + }); + + skippedKeys.forEach((key) => delete data[key]); + return data; +}