ts-force icon indicating copy to clipboard operation
ts-force copied to clipboard

Treat duplicate related instances as single reference

Open ChuckJonas opened this issue 6 years ago • 2 comments

Consider the following query:

SELECT Id, Owner.Id, Owner.Name FROM Account

Result:

AccountId Owner.Id Owner.Name
001 101 John Doe
002 101 John Doe
003 102 Micheal Jordan

ts-force will translate EVERY related Owner to a new User instance, even though, Accounts 001 & 002 both have the same 101 Owner.

This is CPU & memory intensive and can potentially lead to a inconsistent state if one object is later mutated:

acc001.owner.Name  = 'Jane Doe';
assert(acc001.owner.id, acc002.owner.id); //passes
assert(acc001.owner.name, acc002.owner.name); //fails

We now have the same "instance" in salesforce with two different name values in memory.

However, maybe this IS how it should function? Taking this same idea to the extreme, we would we would track a single instance of an SObject globally, which I'm fairly certain would lead to complicated side effects and is a bad idea...

ChuckJonas avatar Apr 18 '19 17:04 ChuckJonas

At the very least, there could be some good performance gains by tracking the different instances during 'mapping' and cloning {...user} instead of running a redundant mapping process. Would be a good intermediate step while I think through the desired behavior.

Maybe even look into using a functional memorized selector (that is GC when the retrieve function returns)

ChuckJonas avatar Apr 18 '19 17:04 ChuckJonas

did some testing an surprisingly I didn't really see any performance benefits to doing this... Not sure it's worth it

ChuckJonas avatar May 10 '19 16:05 ChuckJonas