← Back to Pull requests

Cut game page queries and cold-start work after deploys #5015

Closed
unknown closed this pull request without merging on Nov 09, 2026 04:12 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 04:07 UTC
Author

<!-- claude-projects-attribution: {"github_login":"connorshea"} -->
_Requested by Connor · project thread_

What I found

  • Sentry has very little data: five sampled game page loads in 24 hours (GetGame 412 ms to 4.2 s). Every one of them landed 13 to 17 minutes after a merge to main, which means on a freshly deployed, cold container, on 1 vCPU. In those traces even trivial work was slow: a MemoryStore write took 22 ms, there was 700 ms of middleware before the controller started, and SELECT games WHERE id = $1 took 280 ms. That looks like CPU contention and cold processes, not slow resolvers.

  • Warm, the Ruby cost is modest. Locally, in production mode with a seeded game that has 30 owners, reviews and favorites, a warm GetGame takes ~45 ms. Stackprof shows no single hot spot: ~45% is ActiveRecord building and loading the connections, ~8% complexity analysis and ~5% static validation. The remainder is spread across graphql-ruby execution.

  • Cold, every worker re-read the schema. Eager loading doesn't load model columns, so after each deploy every Puma worker's first game page made ~50 catalog queries on top of its own.
  • Changes (one commit each)

    1. Load model schemas in Puma's master before forking (ProcessWarmup, a before_fork hook). Columns, attribute methods and the operation allowlist's canonical documents are built once and inherited by both workers. It never raises: if it fails, the workers just do the work themselves as before. Locally, the first page load after boot went from ~260 ms to ~175 ms with a ~0.1 ms database round trip. In prod each saved query is also a network round trip.
    2. Load both kinds of library events in one query per table. preload_eventables grouped events by category, so add_to_library and change_completion_status each loaded events_game_purchase_events, their library entries, owners, games and covers separately.
    3. Only preload activity events' games when the query reads them. The nodes field on EventConnectionType now gets the lookahead. A game's activity list never selects eventable.game, so it no longer loads every event's game plus cover attachment, blob and variant records. The global and profile feeds are unchanged. GetGameActivity: 21 → 9 queries, 26 → 16 ms locally.
    4. game(wikidataId: null) returns null. Before, an explicit null passed validation and returned whichever game without that ID Postgres found first. This also keeps the next commit's un-LIMITed query safe.
    5. Load a game and its cover URL's records in one query. When coverUrl is selected, the resolver eager loads attachment → blob → variant record → variant attachment → variant blob in the same joined query as the game, instead of five serial round trips. GetGame: 31 → 26 queries.

    | Operation (local, warm) | Before | After |
    |---|---|---|
    | GetGame | 31 queries, ~45 ms | 26 queries, ~46 ms |
    | GetGameActivity | 21 queries, ~26 ms | 9 queries, ~16 ms |
    | GetGameReviews | 11 queries, ~28 ms | unchanged |
    | GetStores | 1 query, ~4 ms | unchanged |

    The local ms barely move for GetGame because local round trips are ~0.1 ms. In prod, five fewer serial round trips matter more.

    Not changed

  • Skipping static validation for allowlisted documents would save ~1.5 ms per request. I left it out: small win, and it's a security-adjacent change.

  • Deterministic variant keys (2 queries per cover or avatar everywhere, including lists) is tracked separately in #5014.
  • Testing

  • bundle exec rspec: 1461 examples, 0 failures. bundle exec rubocop: no offenses.

  • New specs: ProcessWarmup, the one-query library event preload, activity skipping and keeping game preloads, the one-query game + cover, a Steam App ID lookup with cover, and the null ID case. I checked that each new query-count spec fails without its change.

  • Booted Puma in production mode with 2 workers locally: workers fork after the warmup and serve GraphQL normally.
  • After this deploys, the 2 vCPU instance and the extra traces from #5011 should show whether the slow samples were cold starts. If warm GetGame is still over ~300 ms in Sentry, the next step would be a Sentry profile of a warm request.

    ---
    _Generated by Claude Code_

    Diff: 553 lines (+414 / -139) across 6 files Reviewer: connorshea Review duration: 4m
    All Vouch review confidence checks passed
    Residual risk 0.49 = Change Risk (0.76) × (1 − Review Confidence (0.35)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.76 · 553 lines diff across 6 files
    0.76
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 32% · Reviewer familiarity: 35%
    35%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.378
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.076
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #5015"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 35.4% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 76.3% (HIGH) · Higher = larger blast radius
    76.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 35.4% · Lower = rushed or shallow review
    35.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 49.2% · Moderate risk
    49.2%