mirror of
https://github.com/nasa/openmct.git
synced 2025-04-09 04:14:32 +00:00
Check that mutation happens only if model has changed (#3751)
* When a mutation is requested, the LegacyObjectAPIInterceptor triggers a second mutatation request - ensure that the model for this 2nd request has some diff from the current model before saving the object. Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
parent
605eeff9d7
commit
aebb5df611
@ -141,11 +141,17 @@ define(
|
||||
if (mutationResult !== false) {
|
||||
// Copy values if result was a different object
|
||||
// (either our clone or some other new thing)
|
||||
if (model !== result) {
|
||||
let modelHasChanged = _.isEqual(model, result) === false;
|
||||
if (modelHasChanged) {
|
||||
copyValues(model, result);
|
||||
}
|
||||
|
||||
model.modified = useTimestamp ? timestamp : now();
|
||||
if (modelHasChanged
|
||||
|| (useTimestamp !== undefined)
|
||||
|| (model.modified === undefined)) {
|
||||
model.modified = useTimestamp ? timestamp : now();
|
||||
}
|
||||
|
||||
notifyListeners(model);
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ export default class CouchObjectProvider {
|
||||
* persist any queued objects
|
||||
* @private
|
||||
*/
|
||||
checkResponse(response, intermediateResponse) {
|
||||
checkResponse(response, intermediateResponse, key) {
|
||||
let requestSuccess = false;
|
||||
const id = response ? response.id : undefined;
|
||||
let rev;
|
||||
@ -113,6 +113,8 @@ export default class CouchObjectProvider {
|
||||
if (this.objectQueue[id].hasNext()) {
|
||||
this.updateQueued(id);
|
||||
}
|
||||
} else {
|
||||
this.objectQueue[key].pending = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,8 +134,7 @@ export default class CouchObjectProvider {
|
||||
}
|
||||
|
||||
//Sometimes CouchDB returns the old rev which fetching the object if there is a document update in progress
|
||||
//Only update the rev if it's the first time we're getting the object from CouchDB. Subsequent revs should only be updated by updates.
|
||||
if (!this.objectQueue[key].pending && !this.objectQueue[key].rev) {
|
||||
if (!this.objectQueue[key].pending) {
|
||||
this.objectQueue[key].updateRevision(response[REV]);
|
||||
}
|
||||
|
||||
@ -458,7 +459,7 @@ export default class CouchObjectProvider {
|
||||
const queued = this.objectQueue[key].dequeue();
|
||||
let document = new CouchDocument(key, queued.model);
|
||||
this.request(key, "PUT", document).then((response) => {
|
||||
this.checkResponse(response, queued.intermediateResponse);
|
||||
this.checkResponse(response, queued.intermediateResponse, key);
|
||||
});
|
||||
|
||||
return intermediateResponse.promise;
|
||||
@ -473,7 +474,7 @@ export default class CouchObjectProvider {
|
||||
const queued = this.objectQueue[key].dequeue();
|
||||
let document = new CouchDocument(key, queued.model, this.objectQueue[key].rev);
|
||||
this.request(key, "PUT", document).then((response) => {
|
||||
this.checkResponse(response, queued.intermediateResponse);
|
||||
this.checkResponse(response, queued.intermediateResponse, key);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user