mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	small changes for better debugging infos
This commit is contained in:
		| @@ -296,9 +296,13 @@ function dynamicRequire(moduleName) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function timeLimit(promise, limitMs) { | function timeLimit(promise, limitMs, errorMessage) { | ||||||
|  |     if (!promise || !promise.then) { // it's not actually a promise | ||||||
|  |         return promise; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // better stack trace if created outside of promise |     // better stack trace if created outside of promise | ||||||
|     const error = new Error('Process exceeded time limit ' + limitMs); |     const error = new Error(errorMessage || `Process exceeded time limit ${limitMs}`); | ||||||
|  |  | ||||||
|     return new Promise((res, rej) => { |     return new Promise((res, rej) => { | ||||||
|         let resolved = false; |         let resolved = false; | ||||||
|   | |||||||
| @@ -43,7 +43,6 @@ const processedEntityChangeIds = new Set(); | |||||||
| function logRows(entityChanges) { | function logRows(entityChanges) { | ||||||
|     const filteredRows = entityChanges.filter(row => |     const filteredRows = entityChanges.filter(row => | ||||||
|         !processedEntityChangeIds.has(row.id) |         !processedEntityChangeIds.has(row.id) | ||||||
|         && row.entityName !== 'recent_notes' |  | ||||||
|         && (row.entityName !== 'options' || row.entityId !== 'openTabs')); |         && (row.entityName !== 'options' || row.entityId !== 'openTabs')); | ||||||
|  |  | ||||||
|     if (filteredRows.length > 0) { |     if (filteredRows.length > 0) { | ||||||
| @@ -103,7 +102,7 @@ function waitForEntityChangeId(desiredEntityChangeId) { | |||||||
|         return Promise.resolve(); |         return Promise.resolve(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     console.debug("Waiting for", desiredEntityChangeId, 'current is', lastProcessedEntityChangeId); |     console.debug(`Waiting for ${desiredEntityChangeId}, last processed is ${lastProcessedEntityChangeId}, last accepted ${lastAcceptedEntityChangeId}`); | ||||||
|  |  | ||||||
|     return new Promise((res, rej) => { |     return new Promise((res, rej) => { | ||||||
|         entityChangeIdReachedListeners.push({ |         entityChangeIdReachedListeners.push({ | ||||||
| @@ -127,7 +126,7 @@ function checkEntityChangeIdListeners() { | |||||||
|         .filter(l => l.desiredEntityChangeId > lastProcessedEntityChangeId); |         .filter(l => l.desiredEntityChangeId > lastProcessedEntityChangeId); | ||||||
|  |  | ||||||
|     entityChangeIdReachedListeners.filter(l => Date.now() > l.start - 60000) |     entityChangeIdReachedListeners.filter(l => Date.now() > l.start - 60000) | ||||||
|         .forEach(l => console.log(`Waiting for entityChangeId ${l.desiredEntityChangeId} while current is ${lastProcessedEntityChangeId} for ${Math.floor((Date.now() - l.start) / 1000)}s`)); |         .forEach(l => console.log(`Waiting for entityChangeId ${l.desiredEntityChangeId} while last processed is ${lastProcessedEntityChangeId} (last accepted ${lastAcceptedEntityChangeId}) for ${Math.floor((Date.now() - l.start) / 1000)}s`)); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function runSafely(syncHandler, syncData) { | async function runSafely(syncHandler, syncData) { | ||||||
| @@ -230,25 +229,6 @@ subscribeToMessages(message => { | |||||||
| }); | }); | ||||||
|  |  | ||||||
| async function processEntityChanges(entityChanges) { | async function processEntityChanges(entityChanges) { | ||||||
|     const missingNoteIds = []; |  | ||||||
|  |  | ||||||
|     for (const {entityName, entity} of entityChanges) { |  | ||||||
|         if (entityName === 'branches' && !(entity.parentNoteId in treeCache.notes)) { |  | ||||||
|             missingNoteIds.push(entity.parentNoteId); |  | ||||||
|         } |  | ||||||
|         else if (entityName === 'attributes' |  | ||||||
|               && entity.type === 'relation' |  | ||||||
|               && entity.name === 'template' |  | ||||||
|               && !(entity.noteId in treeCache.notes)) { |  | ||||||
|  |  | ||||||
|             missingNoteIds.push(entity.value); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     if (missingNoteIds.length > 0) { |  | ||||||
|         await treeCache.reloadNotes(missingNoteIds); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     const loadResults = new LoadResults(treeCache); |     const loadResults = new LoadResults(treeCache); | ||||||
|  |  | ||||||
|     for (const ec of entityChanges.filter(ec => ec.entityName === 'notes')) { |     for (const ec of entityChanges.filter(ec => ec.entityName === 'notes')) { | ||||||
| @@ -391,6 +371,25 @@ async function processEntityChanges(entityChanges) { | |||||||
|         loadResults.addOption(ec.entity.name); |         loadResults.addOption(ec.entity.name); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     const missingNoteIds = []; | ||||||
|  |  | ||||||
|  |     for (const {entityName, entity} of entityChanges) { | ||||||
|  |         if (entityName === 'branches' && !(entity.parentNoteId in treeCache.notes)) { | ||||||
|  |             missingNoteIds.push(entity.parentNoteId); | ||||||
|  |         } | ||||||
|  |         else if (entityName === 'attributes' | ||||||
|  |             && entity.type === 'relation' | ||||||
|  |             && entity.name === 'template' | ||||||
|  |             && !(entity.value in treeCache.notes)) { | ||||||
|  |  | ||||||
|  |             missingNoteIds.push(entity.value); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (missingNoteIds.length > 0) { | ||||||
|  |         await treeCache.reloadNotes(missingNoteIds); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     if (!loadResults.isEmpty()) { |     if (!loadResults.isEmpty()) { | ||||||
|         if (loadResults.hasAttributeRelatedChanges()) { |         if (loadResults.hasAttributeRelatedChanges()) { | ||||||
|             noteAttributeCache.invalidate(); |             noteAttributeCache.invalidate(); | ||||||
|   | |||||||
| @@ -91,7 +91,7 @@ export default class Component { | |||||||
|             console.log(`Call to ${fun.name} in ${this.componentId} took ${took}ms`); |             console.log(`Call to ${fun.name} in ${this.componentId} took ${took}ms`); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         await promise; |         await utils.timeLimit(promise, 25000, `Time limit failed on ${this.constructor.name} with ${fun.name}`); | ||||||
|  |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1126,6 +1126,10 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|                 node = await this.expandToNote(nextNotePath, false); |                 node = await this.expandToNote(nextNotePath, false); | ||||||
|  |  | ||||||
|                 if (node) { |                 if (node) { | ||||||
|  |                     // FIXME: this is conceptually wrong | ||||||
|  |                     //        here note tree is responsible for updating global state of the application | ||||||
|  |                     //        this should be done by tabcontext / tabmanager and note tree should only listen to | ||||||
|  |                     //        changes in active note and just set the "active" state | ||||||
|                     await appContext.tabManager.getActiveTabContext().setNote(nextNotePath); |                     await appContext.tabManager.getActiveTabContext().setNote(nextNotePath); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -246,9 +246,13 @@ function getNoteTitle(filePath, replaceUnderscoresWithSpaces, noteMeta) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function timeLimit(promise, limitMs) { | function timeLimit(promise, limitMs, errorMessage) { | ||||||
|  |     if (!promise || !promise.then) { // it's not actually a promise | ||||||
|  |         return promise; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // better stack trace if created outside of promise |     // better stack trace if created outside of promise | ||||||
|     const error = new Error('Process exceeded time limit ' + limitMs); |     const error = new Error(errorMessage || `Process exceeded time limit ${limitMs}`); | ||||||
|  |  | ||||||
|     return new Promise((res, rej) => { |     return new Promise((res, rej) => { | ||||||
|         let resolved = false; |         let resolved = false; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user