mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	fix filling entity changes from Options' Advanced tab, closes #1898
This commit is contained in:
		
							parent
							
								
									03f3e46f8b
								
							
						
					
					
						commit
						b1131844d6
					
				@ -80,31 +80,37 @@ function cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey) {
 | 
				
			|||||||
function fillEntityChanges(entityName, entityPrimaryKey, condition = '') {
 | 
					function fillEntityChanges(entityName, entityPrimaryKey, condition = '') {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey);
 | 
					        cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey);
 | 
				
			||||||
 | 
					        const repository = require("./repository.js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const entityIds = sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName}`
 | 
					        sql.transactional(() => {
 | 
				
			||||||
            + (condition ? ` WHERE ${condition}` : ''));
 | 
					            const entityIds = sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName}`
 | 
				
			||||||
 | 
					                + (condition ? ` WHERE ${condition}` : ''));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let createdCount = 0;
 | 
					            let createdCount = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const entityId of entityIds) {
 | 
					            for (const entityId of entityIds) {
 | 
				
			||||||
            const existingRows = sql.getValue("SELECT COUNT(1) FROM entity_changes WHERE entityName = ? AND entityId = ?", [entityName, entityId]);
 | 
					                const existingRows = sql.getValue("SELECT COUNT(1) FROM entity_changes WHERE entityName = ? AND entityId = ?", [entityName, entityId]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // we don't want to replace existing entities (which would effectively cause full resync)
 | 
					                // we don't want to replace existing entities (which would effectively cause full resync)
 | 
				
			||||||
            if (existingRows === 0) {
 | 
					                if (existingRows === 0) {
 | 
				
			||||||
                createdCount++;
 | 
					                    createdCount++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                sql.insert("entity_changes", {
 | 
					                    const entity = repository.getEntity(`SELECT * FROM ${entityName} WHERE ${entityPrimaryKey} = ?`, [entityId]);
 | 
				
			||||||
                    entityName: entityName,
 | 
					
 | 
				
			||||||
                    entityId: entityId,
 | 
					                    addEntityChange({
 | 
				
			||||||
                    sourceId: "SYNC_FILL",
 | 
					                        entityName,
 | 
				
			||||||
                    isSynced: 1
 | 
					                        entityId,
 | 
				
			||||||
                });
 | 
					                        hash: entity.generateHash(),
 | 
				
			||||||
 | 
					                        isErased: false,
 | 
				
			||||||
 | 
					                        utcDateChanged: entity.getUtcDateChanged()
 | 
				
			||||||
 | 
					                    }, null);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (createdCount > 0) {
 | 
					            if (createdCount > 0) {
 | 
				
			||||||
            log.info(`Created ${createdCount} missing entity changes for ${entityName}.`);
 | 
					                log.info(`Created ${createdCount} missing entity changes for ${entityName}.`);
 | 
				
			||||||
        }
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (e) {
 | 
					    catch (e) {
 | 
				
			||||||
        // this is to fix migration from 0.30 to 0.32, can be removed later
 | 
					        // this is to fix migration from 0.30 to 0.32, can be removed later
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user