Skip to content

Fix n+1 queries#1633

Open
ChrisLovering wants to merge 3 commits into
mainfrom
fix-n+1-queries
Open

Fix n+1 queries#1633
ChrisLovering wants to merge 3 commits into
mainfrom
fix-n+1-queries

Conversation

@ChrisLovering

Copy link
Copy Markdown
Member

No description provided.

Since the role validator was in the model, a query to the roles table had to be ran for each row returned by the user query.

Moving this validation to the serialiser allowed all roles to be validated in the same query as the fetch.

Since the validation is done at the serialiser level, this removed the need for the validators to be in the model at all.
@ChrisLovering ChrisLovering requested review from jb3 and jchristgit July 6, 2026 21:02
@ChrisLovering ChrisLovering requested a review from MarkKoz as a code owner July 6, 2026 21:02
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for pydis-static ready!

Name Link
🔨 Latest commit f7b8d0c
🔍 Latest deploy log https://app.netlify.com/projects/pydis-static/deploys/6a4cf6327fad200009bfbe00
😎 Deploy Preview https://deploy-preview-1633--pydis-static.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coveralls

coveralls commented Jul 6, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — fix-n+1-queries into main

depth = 1
list_serializer_class = UserListSerializer

def validate_roles(self, roles: list[int]) -> list[int]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this covered by tests?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The existing user test will cover this, even tough it's moved from model to serialiser.
https://github.com/python-discord/site/blob/main/pydis_site/apps/api/tests/test_users.py#L110-L122

However, I have noticed it doens't assert the response detail, nor do we have coverage for PATCH (single, nor bulk), so have added all of that in f7b8d0c

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.

3 participants