[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

View File

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