feat: do a single query to get all resource ids instead of a recursiv… #1132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://oat-sa.atlassian.net/browse/ADF-1686
https://oat-sa.atlassian.net/browse/ADF-1805
Goal
The current
getInstances()
was executing behind the scenes several queries and loading objects into memory just to build the the predicate/object comparison as show bellow. For instance, if I have a class with 100 subclasses, it was executing 100 queries and loading 100 objects in memory. Not to mentioned that also uses grouping and HAVING, so bringing more results than necessary.*This is how the query was looking like on the server side.
Solution
Use a single recursive query, avoiding hundreds of extra queries and objects to be load in memory. After this new query was introduced we had an improvement of 200% in RAM for the DB servers.
The new query is more expensive if the class select has little nested classes, but for huge databases, it is more efficient.
Totals:
Query analysis
Related PRs