mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
add memberId to entity_changes to avoid having to resend all changes second time
This commit is contained in:
@@ -123,13 +123,36 @@ function forceNoteSync(req) {
|
||||
function getChanged(req) {
|
||||
const startTime = Date.now();
|
||||
|
||||
const lastEntityChangeId = parseInt(req.query.lastEntityChangeId);
|
||||
let lastEntityChangeId = parseInt(req.query.lastEntityChangeId);
|
||||
const clientMemberId = req.query.memberId;
|
||||
let filteredEntityChanges = [];
|
||||
|
||||
const entityChanges = sql.getRows("SELECT * FROM entity_changes WHERE isSynced = 1 AND id > ? LIMIT 1000", [lastEntityChangeId]);
|
||||
while (filteredEntityChanges.length === 0) {
|
||||
const entityChanges = sql.getRows(`
|
||||
SELECT *
|
||||
FROM entity_changes
|
||||
WHERE isSynced = 1
|
||||
AND id > ?
|
||||
ORDER BY id
|
||||
LIMIT 1000`, [lastEntityChangeId]);
|
||||
|
||||
if (entityChanges.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
filteredEntityChanges = entityChanges.filter(ec => ec.memberId !== clientMemberId);
|
||||
}
|
||||
|
||||
const entityChangesRecords = syncService.getEntityChangesRecords(filteredEntityChanges);
|
||||
|
||||
if (entityChangesRecords.length > 0) {
|
||||
lastEntityChangeId = entityChangesRecords[entityChangesRecords.length - 1].entityChange.id;
|
||||
}
|
||||
|
||||
const ret = {
|
||||
entityChanges: syncService.getEntityChangesRecords(entityChanges),
|
||||
maxEntityChangeId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1')
|
||||
entityChanges: entityChangesRecords,
|
||||
maxEntityChangeId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1'),
|
||||
lastEntityChangeId
|
||||
};
|
||||
|
||||
if (ret.entityChanges.length > 0) {
|
||||
@@ -174,10 +197,10 @@ function update(req) {
|
||||
}
|
||||
}
|
||||
|
||||
const {entities} = body;
|
||||
const {entities, memberId} = body;
|
||||
|
||||
for (const {entityChange, entity} of entities) {
|
||||
syncUpdateService.updateEntity(entityChange, entity);
|
||||
syncUpdateService.updateEntity(entityChange, entity, memberId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user