Skip to content

perf(models): Add caching for Organization.default_owner_id#106560

Merged
beezz merged 2 commits intomasterfrom
perf/cache-organization-default-owner-id
Jan 20, 2026
Merged

perf(models): Add caching for Organization.default_owner_id#106560
beezz merged 2 commits intomasterfrom
perf/cache-organization-default-owner-id

Conversation

@beezz
Copy link
Contributor

@beezz beezz commented Jan 20, 2026

Add Django cache layer for the default_owner_id property on the Organization model to reduce database queries. This property is frequently accessed for analytics purposes and caching reduces load on the database.

Implementation details:

  • Cache key pattern: org.default_owner_id:{org_id}
  • TTL configurable via organization.default-owner-id-cache-ttl option (default: 5 minutes)
  • Uses sentinel value (-1) to properly cache the "no owner" case
  • Instance-level cache (_default_owner_id) preserved for request lifetime

Files changed:

  • src/sentry/options/defaults.py - Register new cache TTL option
  • src/sentry/models/organization.py - Add caching logic to property

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Add Django cache layer for the default_owner_id property to reduce
database queries. The property is frequently accessed for analytics
and this caching reduces load on the database.

Cache behavior:
- TTL configurable via "organization.default-owner-id-cache-ttl" option
- Default: 5 minutes (300 seconds)
- Uses sentinel value (-1) to cache "no owner" case
- Instance-level cache preserved for request lifetime

Co-Authored-By: Claude <noreply@anthropic.com>
@beezz beezz requested a review from a team as a code owner January 20, 2026 12:13
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 20, 2026
Add class-level type annotation to fix mypy error:
"Cannot determine type of _default_owner_id"

Co-Authored-By: Claude <noreply@anthropic.com>
@beezz beezz merged commit 1938a62 into master Jan 20, 2026
66 checks passed
@beezz beezz deleted the perf/cache-organization-default-owner-id branch January 20, 2026 14:13
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 2026
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.

2 participants