eclipse-emfcloud / emfcloud-modelserver

Modelserver component
Other
40 stars 21 forks source link

API V2: ModelServerClient sometimes sends empty requests #190

Open CamilleLetavernier opened 2 years ago

CamilleLetavernier commented 2 years ago

When generating a Json Patch by comparing 2 states of the model, we sometimes end up with an empty patch (When both models are identical). When using this empty patch with modelServerClient.edit(), this results in a no-op request.

Moreover, when combining this with Transactions (org.eclipse.emfcloud.modelserver.emf.common.ModelServerEditingDomain.closeCompoundCommand()), the resulting CompoundCommand is empty, thus unexecutable. This causes a runtime exception for the transaction.

To avoid empty requests an unnecessary exceptions, we should patch the ModelServerClientV2 to immediately ignore empty patches and avoid the client-server roundtrip entirely.

Currently, the workaround is that all client applications should guard against empty patches:

const patch = jsonpatch.compare(
    originalModel,
    updatedModel
);
if (patch.length === 0) {
    return;
}

const editResult = await this.modelServerClient.edit(
    this.modeluri,
    patch
);
...