mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	use entity changes instead of actual tables to fill in sector to sync, fixes #1809
This commit is contained in:
		
							parent
							
								
									7672f22ce0
								
							
						
					
					
						commit
						f0cc3d0bcd
					
				| @ -200,9 +200,7 @@ function queueSector(req) { | ||||
|     const entityName = utils.sanitizeSqlIdentifier(req.params.entityName); | ||||
|     const sector = utils.sanitizeSqlIdentifier(req.params.sector); | ||||
| 
 | ||||
|     const entityPrimaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName; | ||||
| 
 | ||||
|     entityChangesService.addEntityChangesForSector(entityName, entityPrimaryKey, sector); | ||||
|     entityChangesService.addEntityChangesForSector(entityName, sector); | ||||
| } | ||||
| 
 | ||||
| module.exports = { | ||||
|  | ||||
| @ -53,22 +53,14 @@ function moveEntityChangeToTop(entityName, entityId) { | ||||
|     addEntityChange(entityName, entityId, hash, null, isSynced); | ||||
| } | ||||
| 
 | ||||
| function addEntityChangesForSector(entityName, entityPrimaryKey, sector) { | ||||
| function addEntityChangesForSector(entityName, sector) { | ||||
|     const startTime = Date.now(); | ||||
|     const repository = require('./repository'); | ||||
| 
 | ||||
|     const entityChanges = sql.getRows(`SELECT * FROM entity_changes WHERE entityName = ? AND SUBSTR(entityId, 1, 1) = ?`, [entityName, sector]); | ||||
| 
 | ||||
|     sql.transactional(() => { | ||||
|         const entityIds = sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName} WHERE SUBSTR(${entityPrimaryKey}, 1, 1) = ?`, [sector]); | ||||
| 
 | ||||
|         for (const entityId of entityIds) { | ||||
|             // retrieving entity one by one to avoid memory issues with note_contents
 | ||||
|             const entity = repository.getEntity(`SELECT * FROM ${entityName} WHERE ${entityPrimaryKey} = ?`, [entityId]); | ||||
| 
 | ||||
|             if (entityName === 'options' && !entity.isSynced) { | ||||
|                 continue | ||||
|             } | ||||
| 
 | ||||
|             insertEntityChange(entityName, entityId, entity.generateHash(), false, entity.getUtcDateChanged(), 'content-check', true); | ||||
|         for (const ec of entityChanges) { | ||||
|             insertEntityChange(entityName, ec.entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced); | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|  | ||||
| @ -245,9 +245,7 @@ async function checkContentHash(syncContext) { | ||||
|     const failedChecks = contentHashService.checkContentHashes(resp.entityHashes); | ||||
| 
 | ||||
|     for (const {entityName, sector} of failedChecks) { | ||||
|         const entityPrimaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName; | ||||
| 
 | ||||
|         entityChangesService.addEntityChangesForSector(entityName, entityPrimaryKey, sector); | ||||
|         entityChangesService.addEntityChangesForSector(entityName, sector); | ||||
| 
 | ||||
|         await syncRequest(syncContext, 'POST', `/api/sync/queue-sector/${entityName}/${sector}`); | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam