1
0
mirror of https://github.com/vrtmrz/obsidian-livesync.git synced 2024-12-12 09:04:06 +02:00
- Now we can verify and repair database again.
This commit is contained in:
vorotamoroz 2022-12-06 17:59:48 +09:00
parent 96b676caf3
commit 840e03a2d3
3 changed files with 35 additions and 19 deletions

View File

@ -1,7 +1,7 @@
import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, RequestUrlParam, requestUrl, TextAreaComponent, MarkdownRenderer, stringifyYaml } from "obsidian"; import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, RequestUrlParam, requestUrl, TextAreaComponent, MarkdownRenderer, stringifyYaml } from "obsidian";
import { DEFAULT_SETTINGS, LOG_LEVEL, ObsidianLiveSyncSettings, RemoteDBSettings } from "./lib/src/types"; import { DEFAULT_SETTINGS, LOG_LEVEL, ObsidianLiveSyncSettings, RemoteDBSettings } from "./lib/src/types";
import { path2id, id2path } from "./utils"; import { path2id, id2path } from "./utils";
import { delay, versionNumberString2Number } from "./lib/src/utils"; import { delay, Semaphore, versionNumberString2Number } from "./lib/src/utils";
import { Logger } from "./lib/src/logger"; import { Logger } from "./lib/src/logger";
import { checkSyncInfo, isCloudantURI } from "./lib/src/utils_couchdb.js"; import { checkSyncInfo, isCloudantURI } from "./lib/src/utils_couchdb.js";
import { testCrypt } from "./lib/src/e2ee_v2"; import { testCrypt } from "./lib/src/e2ee_v2";
@ -1367,21 +1367,28 @@ ${stringifyYaml(pluginConfig)}`;
.setDisabled(false) .setDisabled(false)
.setWarning() .setWarning()
.onClick(async () => { .onClick(async () => {
const semaphore = Semaphore(10);
const files = this.app.vault.getFiles(); const files = this.app.vault.getFiles();
Logger("Verify and repair all files started", LOG_LEVEL.NOTICE, "verify");
// const notice = NewNotice("", 0);
let i = 0; let i = 0;
for (const file of files) { const processes = files.map(e => (async (file) => {
i++; const releaser = await semaphore.acquire(1, "verifyAndRepair");
Logger(`Update into ${file.path}`);
Logger(`${i}/${files.length}\n${file.path}`, LOG_LEVEL.NOTICE, "verify");
try { try {
await this.plugin.updateIntoDB(file); Logger(`Update into ${file.path}`);
await this.plugin.updateIntoDB(file, false, null, true);
i++;
Logger(`${i}/${files.length}\n${file.path}`, LOG_LEVEL.NOTICE, "verify");
} catch (ex) { } catch (ex) {
Logger("could not update:"); i++;
Logger(`Error while verifyAndRepair`, LOG_LEVEL.NOTICE);
Logger(ex); Logger(ex);
} finally {
releaser();
} }
} }
)(e));
await Promise.all(processes);
Logger("done", LOG_LEVEL.NOTICE, "verify"); Logger("done", LOG_LEVEL.NOTICE, "verify");
}) })
); );

@ -1 +1 @@
Subproject commit 300bf7e9b1b240bf9ef9d55bde10d7dde741839e Subproject commit a13d921fb7e4b79232fb040e257b3b06151b2bfa

View File

@ -2192,7 +2192,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
} }
async updateIntoDB(file: TFile, initialScan?: boolean, cache?: CacheData) { async updateIntoDB(file: TFile, initialScan?: boolean, cache?: CacheData, force?: boolean) {
if (!this.isTargetFile(file)) return; if (!this.isTargetFile(file)) return;
if (shouldBeIgnored(file.path)) { if (shouldBeIgnored(file.path)) {
return; return;
@ -2234,6 +2234,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
if (recentlyTouched(file)) { if (recentlyTouched(file)) {
return true; return true;
} }
try {
const old = await this.localDatabase.getDBEntry(fullPath, null, false, false); const old = await this.localDatabase.getDBEntry(fullPath, null, false, false);
if (old !== false) { if (old !== false) {
const oldData = { data: old.data, deleted: old._deleted || old.deleted, }; const oldData = { data: old.data, deleted: old._deleted || old.deleted, };
@ -2244,6 +2245,14 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
} }
// d._rev = old._rev; // d._rev = old._rev;
} }
} catch (ex) {
if (force) {
Logger(msg + "Error, Could not check the diff for the old one." + (force ? "force writing." : "") + fullPath + ((d._deleted || d.deleted) ? " (deleted)" : ""), LOG_LEVEL.VERBOSE);
} else {
Logger(msg + "Error, Could not check the diff for the old one." + fullPath + ((d._deleted || d.deleted) ? " (deleted)" : ""), LOG_LEVEL.VERBOSE);
}
return !force;
}
return false; return false;
}); });
if (isNotChanged) return; if (isNotChanged) return;