use entity changes instead of actual tables to fill in sector to sync, fixes #1809

This commit is contained in:
zadam 2021-04-04 22:02:40 +02:00
parent 7672f22ce0
commit f0cc3d0bcd
3 changed files with 7 additions and 19 deletions

View file

@ -200,9 +200,7 @@ function queueSector(req) {
const entityName = utils.sanitizeSqlIdentifier(req.params.entityName); const entityName = utils.sanitizeSqlIdentifier(req.params.entityName);
const sector = utils.sanitizeSqlIdentifier(req.params.sector); const sector = utils.sanitizeSqlIdentifier(req.params.sector);
const entityPrimaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName; entityChangesService.addEntityChangesForSector(entityName, sector);
entityChangesService.addEntityChangesForSector(entityName, entityPrimaryKey, sector);
} }
module.exports = { module.exports = {

View file

@ -53,22 +53,14 @@ function moveEntityChangeToTop(entityName, entityId) {
addEntityChange(entityName, entityId, hash, null, isSynced); addEntityChange(entityName, entityId, hash, null, isSynced);
} }
function addEntityChangesForSector(entityName, entityPrimaryKey, sector) { function addEntityChangesForSector(entityName, sector) {
const startTime = Date.now(); 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(() => { sql.transactional(() => {
const entityIds = sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName} WHERE SUBSTR(${entityPrimaryKey}, 1, 1) = ?`, [sector]); for (const ec of entityChanges) {
insertEntityChange(entityName, ec.entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced);
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);
} }
}); });

View file

@ -245,9 +245,7 @@ async function checkContentHash(syncContext) {
const failedChecks = contentHashService.checkContentHashes(resp.entityHashes); const failedChecks = contentHashService.checkContentHashes(resp.entityHashes);
for (const {entityName, sector} of failedChecks) { for (const {entityName, sector} of failedChecks) {
const entityPrimaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName; entityChangesService.addEntityChangesForSector(entityName, sector);
entityChangesService.addEntityChangesForSector(entityName, entityPrimaryKey, sector);
await syncRequest(syncContext, 'POST', `/api/sync/queue-sector/${entityName}/${sector}`); await syncRequest(syncContext, 'POST', `/api/sync/queue-sector/${entityName}/${sector}`);
} }