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

[#5199] Optimize /project/children endpoint #5204

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

MichaelAkvo
Copy link
Contributor

@MichaelAkvo MichaelAkvo commented Jan 26, 2023

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

  • Manual testing

After testing with the Orange Knowledge Program, the request took 3s to load everything instead of 22-30s previously.

Closes #5199

# 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.
@MichaelAkvo MichaelAkvo force-pushed the bug/5199-/project/children-endpoint-is-slow branch from 3a92d56 to 7b8a83e Compare January 30, 2023 09:47
@coveralls
Copy link
Collaborator

Coverage Status

Coverage: 68.18% (+0.03%) from 68.146% when pulling 7b8a83e on bug/5199-/project/children-endpoint-is-slow into b4ff56c on master.

@zuhdil zuhdil merged commit e5137e4 into master Mar 10, 2023
@zuhdil zuhdil deleted the bug/5199-/project/children-endpoint-is-slow branch March 10, 2023 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: /project/children endpoint is slow
3 participants