Skip to content

perf(access): only do demo mode checks if demo mode#88993

Merged
JoshFerge merged 1 commit into
masterfrom
jferg/optimize-code
Apr 8, 2025
Merged

perf(access): only do demo mode checks if demo mode#88993
JoshFerge merged 1 commit into
masterfrom
jferg/optimize-code

Conversation

@JoshFerge

@JoshFerge JoshFerge commented Apr 8, 2025

Copy link
Copy Markdown
Member

see #inc-1104. our database load is getting to be quite high. one of the biggest sources is SELECT queries on the organization table. Looking at the queries module and from there exemplar traces and profiles, it was determined the bulk of these queries come from our permissions middleware.

The first thing I've noticed to optimize is that regardless of a user being demo mode or not, we still do these queries to get the organization right now. This is unneeded work, and can be skipped if it's not the demo user.

This PR moves the logic so we only do these extra checks if we're in demo mode.

This runs most requests, so this should provide some relief on our database.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 8, 2025
@JoshFerge JoshFerge requested review from a team April 8, 2025 00:12
@JoshFerge JoshFerge changed the title perf(access): only do work if demo mode perf(access): only do demo mode checks if demo mode Apr 8, 2025
@JoshFerge JoshFerge marked this pull request as ready for review April 8, 2025 00:13
@JoshFerge JoshFerge requested a review from a team as a code owner April 8, 2025 00:13
@JoshFerge JoshFerge requested a review from a team April 8, 2025 00:13

@obostjancic obostjancic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Thanks for doing this!

@JoshFerge JoshFerge merged commit b3d061b into master Apr 8, 2025
@JoshFerge JoshFerge deleted the jferg/optimize-code branch April 8, 2025 14:11
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
see #inc-1104. our database load is getting to be quite high. one of the
biggest sources is SELECT queries on the organization table. Looking at
the [queries
module](https://sentry.sentry.io/insights/backend/database/spans/span/c40fc66225c6f13e?environment=de&project=1&statsPeriod=30d&transaction=%2Fapi%2F0%2Fprojects%2F%7Borganization_id_or_slug%7D%2F%7Bproject_id_or_slug%7D%2Ffiles%2Fdsyms%2F&transactionMethod=GET)
and from there exemplar traces and
[profiles](https://sentry.sentry.io/explore/profiling/profile/sentry/feff8345eacd4440af7d4721ffa3c684/flamegraph/?colorCoding=by%20system%20vs%20application%20frame&fov=0%2C93%2C88763000%2C14&query=organiza&sorting=call%20order&tid=136381799052992&view=top%20down),
it was determined the bulk of these queries come from our permissions
middleware.

The first thing I've noticed to optimize is that regardless of a user
being demo mode or not, we still do these queries to get the
organization right now. This is unneeded work, and can be skipped if
it's not the demo user.

This PR moves the logic so we only do these extra checks if we're in
demo mode.

This runs most requests, so this should provide some relief on our
database.
Christinarlong pushed a commit that referenced this pull request Apr 10, 2025
see #inc-1104. our database load is getting to be quite high. one of the
biggest sources is SELECT queries on the organization table. Looking at
the [queries
module](https://sentry.sentry.io/insights/backend/database/spans/span/c40fc66225c6f13e?environment=de&project=1&statsPeriod=30d&transaction=%2Fapi%2F0%2Fprojects%2F%7Borganization_id_or_slug%7D%2F%7Bproject_id_or_slug%7D%2Ffiles%2Fdsyms%2F&transactionMethod=GET)
and from there exemplar traces and
[profiles](https://sentry.sentry.io/explore/profiling/profile/sentry/feff8345eacd4440af7d4721ffa3c684/flamegraph/?colorCoding=by%20system%20vs%20application%20frame&fov=0%2C93%2C88763000%2C14&query=organiza&sorting=call%20order&tid=136381799052992&view=top%20down),
it was determined the bulk of these queries come from our permissions
middleware.

The first thing I've noticed to optimize is that regardless of a user
being demo mode or not, we still do these queries to get the
organization right now. This is unneeded work, and can be skipped if
it's not the demo user.

This PR moves the logic so we only do these extra checks if we're in
demo mode.

This runs most requests, so this should provide some relief on our
database.
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants