tracker_api
tracker_api copied to clipboard
double request when call eager loaded associations (owners, tasks, comments)
In story resource, when we eager load association (owners, tasks, comments) and the association has empty value, then it'll try to fetch the information again. Is it an expected behavior?
def owners(params = {})
if params.blank? && @owners.present?
@owners
else
@owners = Endpoints::StoryOwners.new(client).get(project_id, id, params)
end
end
I can see how in your case that is not the desired behavior. I don't think it is right to build in knowledge of the eager loading in the client. I think a good solution is to keep the knowledge with the user and add a param that allows the user to force a load of data or not depending on their situation.
I think it should return the @owners
if it is not undefined
or nil
. When you eager load and there are no owners then @owners
should be an empty array. This is valid.
If params are passed then the load should be forced as well. Same behavior as today.
If @owners
is an empty array and you want to force a load then maybe there should be a reload
param that allows the user to reload the cache from the server.
The problem with the current code is that Virtus is nullifying blank (strings, arrays, etc) during coercion. This behavior is needed for the dirty checking feature. Not a simple fix.
I'm looking into replacing Virtus with some of the http://dry-rb.org/ libraries. I wrote a test for your case that is failing now and will make sure it passes in the rewrite.