Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
reduce flickering of import by disabling entityChanges notification of frontend
zadame78b495bd3bd
diff --git a/src/routes/api/import.js b/src/routes/api/import.jsindex 9b699f4465..cd6ace2cc1 100644--- a/src/routes/api/import.js+++ b/src/routes/api/import.js@@ -42,6 +42,9 @@ async function importToBranch(req) {// and may produce unintended consequencescls.disableEntityEvents();+ // eliminate flickering during import+ cls.ignoreEntityChanges();+let note; // typically root of the import - client can show it after finishing the importconst taskContext = TaskContext.getInstance(taskId, 'import', options);diff --git a/src/services/cls.js b/src/services/cls.jsindex a7b10e802b..e4d238a2e1 100644--- a/src/services/cls.js+++ b/src/services/cls.js@@ -53,6 +53,10 @@ function getAndClearEntityChanges() {}function addEntityChange(entityChange) {+ if (namespace.get('ignoreEntityChanges')) {+ return;+ }+const entityChanges = namespace.get('entityChanges') || [];entityChanges.push(entityChange);@@ -69,7 +73,11 @@ function getEntityFromCache(entityName, entityId) {}function setEntityToCache(entityName, entityId, entity) {- return namespace.set(entityName + '-' + entityId, entity);+ namespace.set(entityName + '-' + entityId, entity);+}++function ignoreEntityChanges() {+ namespace.set('ignoreEntityChanges', true);}module.exports = {@@ -87,5 +95,6 @@ module.exports = {getAndClearEntityChanges,addEntityChange,getEntityFromCache,- setEntityToCache+ setEntityToCache,+ ignoreEntityChanges};