Skip to content

Split ResourceDonut's two ways of answering a hit into compositions - #330

Merged
koriym merged 3 commits into
1.xfrom
split-resource-donut
Nov 29, 2026
Merged

koriym merged 3 commits into
1.xfrom
split-resource-donut

Conversation

@koriym

@koriym koriym commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

ResourceDonut answered a hit in one of two ways and told them apart by a null $body. Each way is now its own @internal DonutCompositionInterface:

  • DonutTemplate – the page is stored as its rendered view with a placeholder for each hole; a hit reads every hole again into it.
  • DonutBody – the page's renderer encodes embedded requests (e.g. JSON), so it is stored as the body it returned; a hit renders that body again with its requests put back.

ResourceDonut keeps the storage state (lifetime, tags, Last-Modified, content hash) and the CacheStoreException boundary around recomposition. Its constructor takes 7 arguments instead of 11.

create() now leaves the rendered view on the response itself, so ResourceDonut::render() is removed. ResourceDonut stays the type of ResourceStorageInterface::getDonut()/saveDonut(), and ResourceDonut::placeholder() is unchanged.

No behavior change; the existing suite covers both compositions.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Cached pages can now be recomposed from either rendered templates or stored response bodies, including embedded resources.
    • Recomposition restores response headers and status codes, helping refreshed pages retain their original response details.
  • Bug Fixes
    • Responses that are not eligible for caching are checked before rendering, avoiding unnecessary rendering work.
    • The original response retains its rendered view after donut creation.

A donut page is stored either as its rendered template with placeholders
or, when its renderer encodes embedded requests, as the body it returned.
ResourceDonut told the two apart by a null body and branched on it in
refresh() and render(). Each is now a DonutCompositionInterface:
DonutTemplate reads every hole again into the template, DonutBody renders
the body again with its requests put back. ResourceDonut keeps the storage
state and the CacheStoreException boundary.

create() renders the template view for the response itself, so render()
is gone and DonutRepository::write() no longer calls it.
@koriym

koriym commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bb8fe79) to head (b21c64f).

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #330   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity       878       876    -2     
===========================================
  Files            121       123    +2     
  Lines           1965      1952   -13     
===========================================
- Hits            1965      1952   -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Donut recomposition now uses composition objects for templates and response bodies. ResourceDonut stores a composition and delegates refresh to it. Creation paths and tests use the new composition-based constructor.

Changes: Donut Composition

Layer / File(s) Summary
Composition contract and implementations
src/DonutCompositionInterface.php, src/DonutTemplate.php, src/DonutBody.php
The new interface defines recomposition. DonutTemplate restores template placeholders, headers, and status code. DonutBody restores stored response data and registers embedded request results as dependencies.
ResourceDonut integration
src/ResourceDonut.php, tests/ResourceDonutTest.php
ResourceDonut is readonly and stores a composition object. Refresh delegates to that object, and creation and state-copy paths retain it. Tests use DonutTemplate and check that create leaves the rendered view on the original response.
Repository and cache alignment
src/DonutRepository.php, tests/AppSurrogateKeyModuleTest.php, tests/DonutCacheTest.php, tests/DonutRepositoryTest.php
The repository no longer renders the donut before storability checks. Repository and cache tests construct ResourceDonut with DonutTemplate.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant ResourceDonut
  participant DonutTemplate
  participant ResourceInterface
  participant ResourceObject
  participant Dependencies
  ResourceDonut->>DonutTemplate: recompose(resource, response object, dependencies)
  DonutTemplate->>ResourceInterface: resolve URI placeholder
  ResourceInterface-->>DonutTemplate: return resource object
  DonutTemplate->>ResourceObject: call toString and substitute resource view
  DonutTemplate->>Dependencies: register resource result
  DonutTemplate->>ResourceObject: assign recomposed view, headers, and status code
Loading

Possibly related PRs

Merge Risk: Minimal · up to b21c6

This refactor moves donut recomposition into separate composition objects without a verified behavior change. No remaining merge-blocking risk was found; the existing test suite is the main safeguard.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: ResourceDonut's two cache-hit recomposition paths (template and body) are split into separate DonutCompositionInterface implementations (DonutTemplate and DonutBody). …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: ResourceDonut's two cache-hit recomposition paths (template and body) are split into separate DonutCompositionInterface implementations (DonutTemplate and DonutBody). The raw summary and objectives confirm this is the primary change, and the title is specific enough for a teammate scanning history.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between bb8fe79 and b21c64f.

Files selected for processing: 9

  • src/DonutBody.php
  • src/DonutCompositionInterface.php
  • src/DonutRepository.php
  • src/DonutTemplate.php
  • src/ResourceDonut.php
  • tests/AppSurrogateKeyModuleTest.php
  • tests/DonutCacheTest.php
  • tests/DonutRepositoryTest.php
  • tests/ResourceDonutTest.php
Files with no reviewable changes: 1

  • src/DonutRepository.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym
koriym merged commit 5f35440 into 1.x Nov 29, 2026
44 checks passed
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