Merge remote-tracking branch 'origin/develop' into feature/server_esm

This commit is contained in:
Elian Doran
2024-07-22 19:58:13 +03:00
56 changed files with 4124 additions and 12044 deletions

View File

@@ -41,15 +41,13 @@ function updateEntities(entityChanges: EntityChangeRecord[], instanceId: string)
atLeastOnePullApplied = true;
}
if (entity) {
updateEntity(entityChange, entity, instanceId, updateContext);
}
updateEntity(entityChange, entity, instanceId, updateContext);
}
logUpdateContext(updateContext);
}
function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string, updateContext: UpdateContext) {
function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string, updateContext: UpdateContext) {
if (!remoteEntityRow && remoteEC.entityName === 'options') {
return; // can be undefined for options with isSynced=false
}
@@ -74,14 +72,13 @@ function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instan
}
}
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]);
function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string, updateContext: UpdateContext) {
const localEC = sql.getRow<EntityChange | undefined>(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]);
const localECIsOlderOrSameAsRemote = (
localEC && localEC.utcDateChanged && remoteEC.utcDateChanged &&
localEC.utcDateChanged <= remoteEC.utcDateChanged);
if (!localEC.utcDateChanged || !remoteEC.utcDateChanged) {
throw new Error("Missing date changed.");
}
if (!localEC || localEC.utcDateChanged <= remoteEC.utcDateChanged) {
if (!localEC || localECIsOlderOrSameAsRemote) {
if (remoteEC.isErased) {
if (localEC?.isErased) {
eraseEntity(remoteEC); // make sure it's erased anyway
@@ -104,7 +101,7 @@ function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow,
}
if (!localEC
|| localEC.utcDateChanged < remoteEC.utcDateChanged
|| localECIsOlderOrSameAsRemote
|| localEC.hash !== remoteEC.hash
|| localEC.isErased !== remoteEC.isErased
) {
@@ -113,7 +110,7 @@ function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow,
return true;
} else if ((localEC.hash !== remoteEC.hash || localEC.isErased !== remoteEC.isErased)
&& localEC.utcDateChanged > remoteEC.utcDateChanged) {
&& !localECIsOlderOrSameAsRemote) {
// the change on our side is newer than on the other side, so the other side should update
entityChangesService.putEntityChangeForOtherInstances(localEC);
@@ -140,7 +137,7 @@ function preProcessContent(remoteEC: EntityChange, remoteEntityRow: EntityRow) {
}
}
function updateNoteReordering(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string) {
function updateNoteReordering(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string) {
if (!remoteEntityRow) {
throw new Error(`Empty note_reordering body for: ${JSON.stringify(remoteEC)}`);
}