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

Fix: Change object.tags eager-load strategy to select-in #996

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

psrok1
Copy link
Member

@psrok1 psrok1 commented Dec 10, 2024

Your checklist for this pull request

  • I've read the contributing guideline.
  • I've tested my changes by building and running the project, and testing changed functionality (if applicable)
  • [ ] I've added automated tests for my change (if applicable, optional)
  • [ ] I've updated documentation to reflect my change (if applicable)

What is the current behaviour?

Current eager-load strategy for Object.tags is joined load. It's the most basic eager-loading strategy in SQLAlchemy, but it doesn't combine well with loading relationships.

When user tries to GET /object/<hash>, object information is returned along with all children/parents hashes and their tags. When we load this information from database using joined load, it results in possibly excessive amount of rows: count(object) x count(tags) where object information is count(tags) repeated along the rows. We see in our instance that for objects with several tags each, it may even cause an OOM condition.

What is the new behaviour?

Object.tags are switched to select-in load strategy. Using this strategy, sqlalchemy generates two queries: one for objects and one for tags for these objects. Then it merges the information from two queries by itself.

This strategy generates much less heavy row set than the joined one.

Test plan

Checked manually if it is actually more efficient than previous strategy

@psrok1 psrok1 merged commit 38a4f65 into master Dec 10, 2024
12 checks passed
@psrok1 psrok1 deleted the fix/change-tags-lazyload-strategy branch December 10, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant