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: Fix evironment metadata N+1 for environments list #2947

Merged
merged 7 commits into from
Nov 13, 2023

Conversation

zachaysan
Copy link
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Isolated the cause of an N+1 query and implemented a fix without forcing it on every caller. We may want to consider reviewing the callers and seeing which of them load metadata as well, since the bulk of the performance enhancement is already complete.

How did you test this code?

One new test. During the testing process I also manually inspecting the types of queries that were generated to ensure that they matched those reported by Sentry.

Copy link

vercel bot commented Nov 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2023 8:44pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2023 8:44pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2023 8:44pm

@github-actions github-actions bot added the api Issue related to the REST API label Nov 9, 2023
Copy link
Contributor

github-actions bot commented Nov 9, 2023

Uffizzi Preview deployment-40416 was deleted.

api/environments/tests/test_views.py Outdated Show resolved Hide resolved
api/environments/tests/test_views.py Outdated Show resolved Hide resolved
api/environments/tests/test_views.py Outdated Show resolved Hide resolved
api/environments/tests/test_views.py Outdated Show resolved Hide resolved
api/permissions/permission_service.py Show resolved Hide resolved
@gagantrivedi gagantrivedi linked an issue Nov 10, 2023 that may be closed by this pull request
Copy link
Member

@gagantrivedi gagantrivedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should try to add new tests under the tests directory only. The tests here should live under /tests/unit/environment/test_views, right @matthewelwell ?

api/environments/tests/test_views.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7d16197) 95.64% compared to head (b08931b) 95.68%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2947      +/-   ##
==========================================
+ Coverage   95.64%   95.68%   +0.04%     
==========================================
  Files        1012     1011       -1     
  Lines       29173    29197      +24     
==========================================
+ Hits        27902    27938      +36     
+ Misses       1271     1259      -12     
Files Coverage Δ
api/conftest.py 98.83% <ø> (+2.32%) ⬆️
api/environments/views.py 96.69% <ø> (+4.13%) ⬆️
api/permissions/permission_service.py 97.50% <100.00%> (+0.09%) ⬆️
.../unit/environments/test_unit_environments_views.py 100.00% <100.00%> (ø)
api/users/models.py 95.07% <ø> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zachaysan
Copy link
Contributor Author

Think we should try to add new tests under the tests directory only. The tests here should live under /tests/unit/environment/test_views, right @matthewelwell ?

Sounds good. I've moved all the tests into the target file, including the one I wrote.

@matthewelwell matthewelwell added this pull request to the merge queue Nov 13, 2023
Merged via the queue into main with commit 7e1c779 Nov 13, 2023
20 checks passed
@matthewelwell matthewelwell deleted the fix/handle_n_plus_one_for_environments_list branch November 13, 2023 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

N+1 metadata query for /api/v1/environments/?project=<id>
5 participants