From fda0df610c7508f801bea47f5f303bee43013ae0 Mon Sep 17 00:00:00 2001 From: 0xRoy <1997roylee@gmail.com> Date: Wed, 31 Jan 2024 03:05:39 +0800 Subject: [PATCH 1/4] bugfix: save is not working after delete document or refinfo --- packages/core/src/storage/kvStore/SimpleKVStore.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/core/src/storage/kvStore/SimpleKVStore.ts b/packages/core/src/storage/kvStore/SimpleKVStore.ts index 208fc52d5d..6f6b83f0f5 100644 --- a/packages/core/src/storage/kvStore/SimpleKVStore.ts +++ b/packages/core/src/storage/kvStore/SimpleKVStore.ts @@ -55,6 +55,11 @@ export class SimpleKVStore extends BaseKVStore { ): Promise { if (key in this.data[collection]) { delete this.data[collection][key]; + + if (this.persistPath) { + await this.persist(this.persistPath, this.fs); // Save the data after deleting the key + } + return true; } return false; From 2b2af4f023748b22f1386b56e6354c5344a6868e Mon Sep 17 00:00:00 2001 From: 0xRoy <1997roylee@gmail.com> Date: Wed, 31 Jan 2024 14:01:34 +0800 Subject: [PATCH 2/4] delete method in SimpleKVStore to remove persist functionality --- packages/core/src/storage/kvStore/SimpleKVStore.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/core/src/storage/kvStore/SimpleKVStore.ts b/packages/core/src/storage/kvStore/SimpleKVStore.ts index 6f6b83f0f5..f63d319b43 100644 --- a/packages/core/src/storage/kvStore/SimpleKVStore.ts +++ b/packages/core/src/storage/kvStore/SimpleKVStore.ts @@ -56,10 +56,6 @@ export class SimpleKVStore extends BaseKVStore { if (key in this.data[collection]) { delete this.data[collection][key]; - if (this.persistPath) { - await this.persist(this.persistPath, this.fs); // Save the data after deleting the key - } - return true; } return false; From 6f6bb961b1437e60dc076a500d8be47c3c6b5370 Mon Sep 17 00:00:00 2001 From: 0xRoy <1997roylee@gmail.com> Date: Wed, 31 Jan 2024 14:02:38 +0800 Subject: [PATCH 3/4] Refactor instanceof check in code to use SimpleKVStore instead of BaseInMemoryKVStore --- packages/core/src/storage/docStore/SimpleDocumentStore.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/core/src/storage/docStore/SimpleDocumentStore.ts b/packages/core/src/storage/docStore/SimpleDocumentStore.ts index 60297928f1..7049cb890e 100644 --- a/packages/core/src/storage/docStore/SimpleDocumentStore.ts +++ b/packages/core/src/storage/docStore/SimpleDocumentStore.ts @@ -8,7 +8,6 @@ import { DEFAULT_PERSIST_DIR, } from "../constants"; import { SimpleKVStore } from "../kvStore/SimpleKVStore"; -import { BaseInMemoryKVStore } from "../kvStore/types"; import { KVDocumentStore } from "./KVDocumentStore"; type SaveDict = Record; @@ -57,10 +56,7 @@ export class SimpleDocumentStore extends KVDocumentStore { fs?: GenericFileSystem, ): Promise { fs = fs || DEFAULT_FS; - if ( - _.isObject(this.kvStore) && - this.kvStore instanceof BaseInMemoryKVStore - ) { + if (_.isObject(this.kvStore) && this.kvStore instanceof SimpleKVStore) { await this.kvStore.persist(persistPath, fs); } } From d66a242f738d71649ac68d95234605d61f4445cb Mon Sep 17 00:00:00 2001 From: 0xRoy <1997roylee@gmail.com> Date: Wed, 31 Jan 2024 14:07:00 +0800 Subject: [PATCH 4/4] remove a empty line --- packages/core/src/storage/kvStore/SimpleKVStore.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/storage/kvStore/SimpleKVStore.ts b/packages/core/src/storage/kvStore/SimpleKVStore.ts index f63d319b43..208fc52d5d 100644 --- a/packages/core/src/storage/kvStore/SimpleKVStore.ts +++ b/packages/core/src/storage/kvStore/SimpleKVStore.ts @@ -55,7 +55,6 @@ export class SimpleKVStore extends BaseKVStore { ): Promise { if (key in this.data[collection]) { delete this.data[collection][key]; - return true; } return false;