[ObjectAPI] Cleanup code and remove possible memory leak (#6269)

* Destroy mutable after refresh
* Check if domainObject supports mutation before getting mutable
This commit is contained in:
Jamie V 2023-02-06 10:53:06 -08:00 committed by GitHub
parent 3c36ba9a71
commit b57974b462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -225,24 +225,21 @@ export default class ObjectAPI {
throw new Error('Provider does not support get!');
}
let objectPromise = provider.get(identifier, abortSignal).then(result => {
let objectPromise = provider.get(identifier, abortSignal).then(domainObject => {
delete this.cache[keystring];
domainObject = this.applyGetInterceptors(identifier, domainObject);
result = this.applyGetInterceptors(identifier, result);
if (result.isMutable) {
result.$refresh(result);
} else {
let mutableDomainObject = this.toMutable(result);
mutableDomainObject.$refresh(result);
if (this.supportsMutation(identifier)) {
const mutableDomainObject = this.toMutable(domainObject);
mutableDomainObject.$refresh(domainObject);
this.destroyMutable(mutableDomainObject);
}
return result;
}).catch((result) => {
console.warn(`Failed to retrieve ${keystring}:`, result);
return domainObject;
}).catch((error) => {
console.warn(`Failed to retrieve ${keystring}:`, error);
delete this.cache[keystring];
result = this.applyGetInterceptors(identifier);
const result = this.applyGetInterceptors(identifier);
return result;
});