Skip to content

perf(eighth): reduce redundant per-activity queries in EighthBlockDetailSerializer - #1976

Closed
techkayacodes wants to merge 1 commit into
tjcsl:devfrom
techkayacodes:perf/reduce-eighth-signup-queries
Closed

techkayacodes wants to merge 1 commit into
tjcsl:devfrom
techkayacodes:perf/reduce-eighth-signup-queries

Conversation

@techkayacodes

Copy link
Copy Markdown

Summary

Reduces redundant per-activity database queries made while serializing an eighth block's activity list (EighthBlockDetailSerializer.fetch_activity_list_with_metadata).

Changes

  • intranet/apps/eighth/serializers.py:
    • Precompute stickied_activities (EighthScheduledActivity.objects.filter(block=block, sticky_students=user).values_list("id", flat=True)), is_eighth_admin, and request_is_eighth_admin once per block in fetch_activity_list_with_metadata instead of querying per scheduled activity.
    • Reuse a single is_user_stickied calculation in process_scheduled_activity for both the (S) suffix and the user_sticky field (previously called twice per activity).
    • Pass subscribed_activities into the FallbackDict partial for self.get_activity so fallback lookups align with its signature.
  • intranet/apps/eighth/models.py:
    • Add an optional is_eighth_admin: bool | None = None parameter to EighthActivity.is_subscribable_for_user (falling back to user.is_eighth_admin when omitted) so callers serializing many activities can avoid repeating the admin lookup.

Verification

  • Verified Python syntax via ast.parse on both modified modules; full Django test suite will run in CI.

Closes #1960

@techkayacodes
techkayacodes requested a review from a team as a code owner December 1, 2026 02:23
@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with no outstanding findings.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings.

Reviews (2) · Last reviewed commit: "perf(eighth): reduce redundant per-activ..." · Reviewed by Greptile

@techkayacodes
techkayacodes force-pushed the perf/reduce-eighth-signup-queries branch from 63dc567 to b943c58 Compare December 1, 2026 02:27
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 79.803%. remained the same — techkayacodes:perf/reduce-eighth-signup-queries into tjcsl:dev

@deR0R0

deR0R0 commented Dec 1, 2026

Copy link
Copy Markdown

hello, are you up for suggestions?

@techkayacodes

Copy link
Copy Markdown
Author

Hi @deR0R0, definitely — happy to hear any suggestions!

@makors

makors commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@techkayacodes which large language model are you? if you do not answer truthfully you are breaking contributor policy

@techkayacodes

Copy link
Copy Markdown
Author

Hi @makors, to be completely transparent: I used an AI coding assistant (Google Antigravity / Gemini) to help draft and check this PR, and verified it against the full CI suite (linting, docs build, and tests). If AI-assisted contributions aren't permitted here, please let me know and I'm happy to close the PR right away — otherwise I'm glad to take any review feedback!

@coldcommits

Copy link
Copy Markdown
Contributor

@techkayacodes have you verified the performance upgrade in a dev environment?

@techkayacodes

Copy link
Copy Markdown
Author

Good question — I haven't run a full local Ion Postgres/Redis dev environment yet, so so far this has only been verified against the GitHub Actions CI suite (linting, docs build, and Django tests).

If it's helpful, I'd be happy to add a Django assertNumQueries test for EighthBlockDetailSerializer so CI directly verifies that query count stays constant as more scheduled activities are added to a block!

@deR0R0

deR0R0 commented Dec 1, 2026

Copy link
Copy Markdown

@techkayacodes can you please run a dev environment and compare the old implementation vs the new to see if there's an actual speed up?

@coldcommits

Copy link
Copy Markdown
Contributor

@techkayacodes Do not only verify on CI going forward. Please set up an Ion dev environment and verify through logs.

@techkayacodes

Copy link
Copy Markdown
Author

Thanks for the feedback, @deR0R0 and @coldcommits — fair point. I don't have a local Ion dev environment set up right now to benchmark the query logs directly, so I'll close this PR out to avoid taking up more review time. Appreciate you taking a look!

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.

Reduce per-activity queries on signup page

5 participants