Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate all references to the same resource #23

Closed
ahatius opened this issue Apr 12, 2016 · 8 comments
Closed

Populate all references to the same resource #23

ahatius opened this issue Apr 12, 2016 · 8 comments
Assignees
Labels
Milestone

Comments

@ahatius
Copy link

ahatius commented Apr 12, 2016

I've got a call that will return multiple entities. I've configured the SpringDataRestAdapter to recursively resolve multiple links.

This actually works fine, but my problem is the filter that ensures that each URL is called only once which leads to unpopulated fields if one of the entities has a link to an resource that was already fetched for another entity. This leaves all references after the first one empty.

While I do appreciate that each URL is only called once (I've already got 29 requests with only one call of SpringDataRestAdapter), it would be extremely useful if other entities that reference the same links would get populated aswell.

@guylabs guylabs self-assigned this Apr 12, 2016
@guylabs
Copy link
Owner

guylabs commented Apr 12, 2016

Hi @ahatius,

can you please provide me an example of what you are doing with the filter and without the filter it works properly right? You can also use the caching of the $http service described here such that you do not call the back end multiple times with the same request: https://docs.angularjs.org/api/ng/service/$http#caching

Thanks and regards,

Guy

@ahatius
Copy link
Author

ahatius commented Apr 12, 2016

Hi Guy

Thanks for the fast reply :)

Actually my wording was not quite correct when I said filter. I'm not using an angular filter, I was actually referencing the comment on line 261 in angular-spring-data-rest-provider.js. According to that every resource will be fetched only once.

However, I tried to copy my JSON responses and noticed that they are way too big to copy in here, so I created a small, simple project which provides an example of my problem. Maybe I'm doing something wrong and that's the reason for my issue.

You can find the example project here. The project just needs to be checked out and started, everything else should be automatically initialized so you just need to navigate to http://localhost:8080/index. I have also added a screenshot of how it looks, what it's supposed to look like and what the final JSON object looks like.

I'd be really glad if you could have a look at it if you have a moment.

@guylabs
Copy link
Owner

guylabs commented Apr 22, 2016

Hi @ahatius,

sorry for my late reply but I hadn't the time to look into it. This nice little project runs and I analyzed your domain model and one issue is that you have cyclic dependencies as shown in this diagram:

cyclic-dependencies

Therefore the problem is that you call the SpringDataRestAdapter recursively and then it will never stop because of this cyclic dependencies.

I will check to add a flag to disable this check that the link was already fetched as this is an issue but then you must not have cyclic dependencies.

I would propose that you remove these dependencies and then update the project and I can check again for the flag such that you get the proper responses.

Would that be ok for you?

Thanks and regards,

Guy

@ahatius
Copy link
Author

ahatius commented Apr 23, 2016

Hi Guy

Thank you very much for that analysis.

I think that should be feasible. I have removed the circular dependencies for the Product, ProductRate and ProductCategory entities in the test project. I have also removed them for the Job and JobDetail entities, although those didn't seem to be problematic.

Cheers,
Ahatius

@guylabs
Copy link
Owner

guylabs commented May 10, 2016

Hey Ahatius,

nice I am glad to hear that. I will try to integrate the new flag as soon as I have more time and then I will do a new release.

Thanks and regards,

Guy

@torsten-sauer
Copy link

torsten-sauer commented Jun 1, 2016

I have the same problem here. I have a directive which loads a tree recursivly from my server (using the recursive=true option for SpringDataRestAdapter.process and given links to follow) . If I add the directive twice on a single page, one tree is fully populated, the other one has only its root nodes.

I can see that the request for the "root nodes" is made twice, but the following requests which dive deeper are done only once and the resolved response is in one case only filled with the root nodes, the other one has all childs that were fetched.

It is very complicated to build up a standalone testcase, but maybe you can have a look at the screenshot. It is a console.log from the two responses. The first is with empty 'childDiagnosisGroups', the second includes them as object. You can see that the link is for both the same, the initial requests are identical. If I make another call to it, it results everytime the full tree. I think this two requests get grouped at some point and the links are followed only once (good for performance), but the resulting data isn't distributed to every call.

spring-data-rest-problem

Hope that helps to explain the problem and make further investigation possible

@guylabs guylabs added this to the 0.4.5 milestone Oct 27, 2016
@guylabs
Copy link
Owner

guylabs commented Oct 28, 2016

Hi

the flag fetchMultiple flag has been added. Read more here in the documentation: https://github.com/guylabs/angular-spring-data-rest#how-to-automatically-fetch-links (nead the end of the section)

I will now release 0.4.5 and then you can update and adapt your projects.

Regards,

Guy

@guylabs guylabs closed this as completed Oct 28, 2016
@ahatius
Copy link
Author

ahatius commented Oct 31, 2016

Thank you very much, will try it out ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants