A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: flush logs every 2 seconds instead of immediately
thecodrre6da6fbc73ef
diff --git a/packages/core/logger.js b/packages/core/logger.jsindex fceefd6b0..8aaeb3880 100644--- a/packages/core/logger.js+++ b/packages/core/logger.js@@ -41,24 +41,36 @@ class DatabaseLogWriter {constructor(storage) {this.storage = storage;this.key = new Date().toLocaleDateString();+ this.queue = [];++ setInterval(() => {+ setTimeout(() => this.flush());+ }, 2000);+ }++ push(message) {+ this.queue.push(message);}- async push(message) {- const logs = await this.read();+ async read() {+ return await this.storage.read(this.key, true);+ }+ async flush() {+ if (this.queue.length <= 0) return;+ const queueCopy = this.queue.slice();+ this.queue = [];++ let logs = await this.read();if (!logs) {await this.rotate();- return this.push(message);+ logs = await this.read();}- logs.push(message);+ logs.push(...queueCopy);await this.storage.write(this.key, logs);}- async read() {- return await this.storage.read(this.key, true);- }-async rotate() {await this.storage.write(this.key, []);const logKeys = (await this.storage.getAllKeys()).sort();