Skip to content

fix(gamedata): planets refetched in one cached batch instead of one request per planet - #64

Merged
jplacht merged 1 commit into
mainfrom
fix/batched-planet-fetch
Oct 1, 2026
Merged

jplacht merged 1 commit into
mainfrom
fix/batched-planet-fetch

Conversation

@jplacht

@jplacht jplacht commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What and why

When planets expired, the frontend refetched every planet with its own GET /data/planet/<id>/ at once (bursts of up to 117 requests per client in production), and POST /data/planets/multiple/ was not cached. This serves planets/multiple from the same per-planet cache entries as the detail endpoint, so the frontend can refetch expired planets in one request.

Changes

  • planets/multiple served from the per-planet PLANET cache entries it shares with GET /data/planet/<id>/ (new CacheManager.respond_many)
  • missing planets built in one queryset and cached per planet; unknown ids omitted, never cached
  • ETag over the member ETags, If-None-Match → 304, Cache-Control: public, max-age=60
  • at most 200 ids per request (400 otherwise)
  • removed the unused GamePlanetSearchService.search_by_planet_natural_id

Deviation: misses skip the per-key stampede lock (they're built in one prefetching query, so the lock would only serialise encoding).

How it was verified

QA: PASS in one round (code review against all 6 acceptance criteria, full walk in the running app).

  • uv run ruff check, ruff format --check, ty check, pytest: pass
  • new tests: same bodies as the detail endpoint in request order, repeat request runs 0 queries, only new planets built, new data after invalidation, 304 on the current ETag, 201 ids → 400
  • running app: ETag, public, max-age=60, 304 on repeat, 400 on 201 ids; the plan editor still loads its planet

Deploy order

Deploy backend first; it is backward compatible (same response shape, the current frontend sends far fewer than 200 ids). Paired frontend PR: PRUNplanner/frontend#534

🤖 Generated with Claude Code

…equest per planet

Findings: F5

- planets/multiple served from the per-planet PLANET cache entries it shares with GET /data/planet/<id>/ (new CacheManager.respond_many)
- missing planets built in one queryset and cached per planet; unknown ids omitted, never cached
- ETag over the member ETags, If-None-Match -> 304, Cache-Control public max-age=60
- at most 200 ids per request (400 otherwise)
- removed the unused GamePlanetSearchService.search_by_planet_natural_id

Spec: specs/2026-09-30-be-05-batched-planet-fetch.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 21 complexity · 0 duplication

Metric Results
Complexity 21
Duplication 0

View in Codacy

🟢 Coverage 97.87% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation ✅ +0.01% coverage variation (-1.00%)
Diff coverage ✅ 97.87% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (927be54) 4600 4391 95.46%
Head commit (a82aafe) 4633 (+33) 4423 (+32) 95.47% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#64) 47 46 97.87%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jplacht
jplacht merged commit aa22a3c into main Oct 1, 2026
6 checks passed
@jplacht
jplacht deleted the fix/batched-planet-fetch branch October 1, 2026 05:25
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.

1 participant