diff --git a/src/localdb.ts b/src/localdb.ts index e932e6a..3714a62 100644 --- a/src/localdb.ts +++ b/src/localdb.ts @@ -276,6 +276,11 @@ export const getSyncMetaMappingByRemoteKeyS3 = async ( throw Error("something bad in sync meta mapping!"); }; +export const clearAllSyncMetaMapping = async (db: lf.DatabaseConnection) => { + const tbl = db.getSchema().table(DEFAULT_TBL_SYNC_MAPPING); + await db.delete().from(tbl).exec(); +}; + export const insertSyncPlanRecord = async ( db: lf.DatabaseConnection, syncPlan: SyncPlanType diff --git a/src/main.ts b/src/main.ts index 099ea44..93d90b0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,7 +11,11 @@ import { TFolder, } from "obsidian"; import * as CodeMirror from "codemirror"; -import { clearAllSyncPlanRecords, DatabaseConnection } from "./localdb"; +import { + clearAllSyncPlanRecords, + clearAllSyncMetaMapping, + DatabaseConnection, +} from "./localdb"; import { prepareDBs, destroyDBs, @@ -318,5 +322,25 @@ class SaveRemoteSettingTab extends PluginSettingTab { new Notice("sync plans history (in db) deleted"); }); }); + + const syncMappingDiv = containerEl.createEl("div"); + syncMappingDiv.createEl("p", { + text: "Sync mappings history stores the actual LOCAL last modified time of the REMOTE objects.", + }); + + syncMappingDiv.createEl("p", { + text: "If the sync mappings history are deleted, unnecessary data exchanges may occur in next-time syncing, because whether a remote object and local object with same name are equivalent or not could not be determined correctly by comparing last modified times.", + }); + + new Setting(containerEl) + .setName("delete sync mappings history in db") + .setDesc("delete sync mappings history in db") + .addButton(async (button) => { + button.setButtonText("Delete Sync Mappings"); + button.onClick(async () => { + await clearAllSyncMetaMapping(this.plugin.db); + new Notice("sync mappings history (in local db) deleted"); + }); + }); } }