mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	server: Fix sync failing if local EC is missing
This commit is contained in:
		| @@ -75,13 +75,12 @@ function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instan | |||||||
| } | } | ||||||
|  |  | ||||||
| function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string, updateContext: UpdateContext) { | function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string, updateContext: UpdateContext) { | ||||||
|     const localEC = sql.getRow<EntityChange>(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]); |     const localEC = sql.getRow<EntityChange | undefined>(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]); | ||||||
|  |     const localECIsOlderThanRemote = ( | ||||||
|  |             localEC && localEC.utcDateChanged && remoteEC.utcDateChanged && | ||||||
|  |             localEC.utcDateChanged <= remoteEC.utcDateChanged); | ||||||
|  |  | ||||||
|     if (!localEC.utcDateChanged || !remoteEC.utcDateChanged) { |     if (!localEC || localECIsOlderThanRemote) { | ||||||
|         throw new Error("Missing date changed."); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     if (!localEC || localEC.utcDateChanged <= remoteEC.utcDateChanged) { |  | ||||||
|         if (remoteEC.isErased) { |         if (remoteEC.isErased) { | ||||||
|             if (localEC?.isErased) { |             if (localEC?.isErased) { | ||||||
|                 eraseEntity(remoteEC); // make sure it's erased anyway |                 eraseEntity(remoteEC); // make sure it's erased anyway | ||||||
| @@ -104,7 +103,7 @@ function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!localEC |         if (!localEC | ||||||
|             || localEC.utcDateChanged < remoteEC.utcDateChanged |             || localECIsOlderThanRemote | ||||||
|             || localEC.hash !== remoteEC.hash |             || localEC.hash !== remoteEC.hash | ||||||
|             || localEC.isErased !== remoteEC.isErased |             || localEC.isErased !== remoteEC.isErased | ||||||
|         ) { |         ) { | ||||||
| @@ -113,7 +112,7 @@ function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, | |||||||
|  |  | ||||||
|         return true; |         return true; | ||||||
|     } else if ((localEC.hash !== remoteEC.hash || localEC.isErased !== remoteEC.isErased) |     } else if ((localEC.hash !== remoteEC.hash || localEC.isErased !== remoteEC.isErased) | ||||||
|                 && localEC.utcDateChanged > remoteEC.utcDateChanged) { |                 && !localECIsOlderThanRemote) { | ||||||
|         // the change on our side is newer than on the other side, so the other side should update |         // the change on our side is newer than on the other side, so the other side should update | ||||||
|         entityChangesService.putEntityChangeForOtherInstances(localEC); |         entityChangesService.putEntityChangeForOtherInstances(localEC); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user