tracker_api icon indicating copy to clipboard operation
tracker_api copied to clipboard

double request when call eager loaded associations (owners, tasks, comments)

Open drselump14 opened this issue 8 years ago • 1 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

drselump14 avatar Feb 13 '17 08:02 drselump14

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.

forest avatar Feb 15 '17 21:02 forest