[#5199] Optimize /project/children endpoint #5204
Merged
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.
TODO / Done
Summarize what has been changed / what has to be done in order to finalize the PR.
Counting children
This was slow because we made a query for each project. Now we get the children and grand children.
A simple dict with each project and a list of their children is then built in python.
Side effect
Paging doesn't work anymore as the queryset includes grand children. Reimplementing it can be done another time if we really do have projects with enormous hierarchies.
Parent retrieval
We already know who the parent is since we're getting its children --> no need to make another query.
Locations
We weren't retrieving related objects, which we now do. Additionally, we iterated over the list of countries twice when one iteration was enough.
Test plan
What tests are necessary to ensure this works or doesn't break anything working
After testing with the Orange Knowledge Program, the request took 3s to load everything instead of 22-30s previously.
Closes #5199