mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	fix backend to frontend sync with waitForSyncId()
This commit is contained in:
		
							parent
							
								
									bcbf1b79c3
								
							
						
					
					
						commit
						e6e41adad0
					
				| @ -100,4 +100,14 @@ export default class LoadResults { | |||||||
|     isOptionReloaded(name) { |     isOptionReloaded(name) { | ||||||
|         this.options.includes(name); |         this.options.includes(name); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     isEmpty() { | ||||||
|  |         return Object.keys(this.noteIdToSourceId).length > 0 | ||||||
|  |             || this.branches.length > 0 | ||||||
|  |             || this.attributes.length > 0 | ||||||
|  |             || this.noteReorderings.length > 0 | ||||||
|  |             || this.noteRevisions.length > 0 | ||||||
|  |             || this.contentNoteIdToSourceId.length > 0 | ||||||
|  |             || this.options.length > 0; | ||||||
|  |     } | ||||||
| } | } | ||||||
| @ -44,7 +44,7 @@ async function handleMessage(event) { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (message.type === 'sync') { |     if (message.type === 'sync') { | ||||||
|         const syncRows = message.data; |         let syncRows = message.data; | ||||||
|         lastPingTs = Date.now(); |         lastPingTs = Date.now(); | ||||||
| 
 | 
 | ||||||
|         $outstandingSyncsCount.html(message.outstandingSyncs); |         $outstandingSyncsCount.html(message.outstandingSyncs); | ||||||
| @ -90,6 +90,8 @@ function waitForSyncId(desiredSyncId) { | |||||||
|         return Promise.resolve(); |         return Promise.resolve(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     console.log("Waiting for", desiredSyncId, 'current is', lastProcessedSyncId); | ||||||
|  | 
 | ||||||
|     return new Promise((res, rej) => { |     return new Promise((res, rej) => { | ||||||
|         syncIdReachedListeners.push({ |         syncIdReachedListeners.push({ | ||||||
|             desiredSyncId, |             desiredSyncId, | ||||||
| @ -322,13 +324,19 @@ async function processSyncRows(syncRows) { | |||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     syncRows.filter(sync => sync.entityName === 'options').forEach(sync => { |     syncRows.filter(sync => sync.entityName === 'options').forEach(sync => { | ||||||
|  |         if (sync.entity.name === 'openTabs') { | ||||||
|  |             return; // only noise
 | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         options.set(sync.entity.name, sync.entity.value); |         options.set(sync.entity.name, sync.entity.value); | ||||||
| 
 | 
 | ||||||
|         loadResults.addOption(sync.entity.name); |         loadResults.addOption(sync.entity.name); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const appContext = (await import("./app_context.js")).default; |     if (!loadResults.isEmpty()) { | ||||||
|     appContext.triggerEvent('entitiesReloaded', {loadResults}); |         const appContext = (await import("./app_context.js")).default; | ||||||
|  |         appContext.triggerEvent('entitiesReloaded', {loadResults}); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default { | export default { | ||||||
|  | |||||||
| @ -98,8 +98,7 @@ async function fillInAdditionalProperties(sync) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function sendPing(client) { | async function sendPing(client) { | ||||||
|     const syncRows = cls.getSyncRows() |     const syncRows = cls.getSyncRows(); | ||||||
|         .filter(r => r.entityName !== 'recent_notes' && (r.entityName !== 'options' || r.entityId !== 'openTabs')); // only noise ...
 |  | ||||||
| 
 | 
 | ||||||
|     for (const sync of syncRows) { |     for (const sync of syncRows) { | ||||||
|         try { |         try { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam