Skip to content

fix(core): cache Content Platform template list across page generations (3.x) - #3534

Merged
lemagnetic merged 1 commit into
3.xfrom
fix/3.x-cp-plp-template-cache
Oct 26, 2026
Merged

lemagnetic merged 1 commit into
3.xfrom
fix/3.x-cp-plp-template-cache

Conversation

@lemagnetic

@lemagnetic lemagnetic commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

Backport of #3526 to 3.x.

3.x has had the same Content Platform (CP) template lookup since v3.100.2 (#3384). The plp/entries/slug/:slug lookup 404s with the default plp schema. On that 404, getMultipleContent paginates listEntries and then fetches every entry to read settings.template.value. So each cold PLP/PDP generation costs ceil(N / 20) + N CP calls, and nothing is reused between page generations. On a store with ~330 PLP entries, that is about 350 CP calls per collection, fired in bursts right after each build.

How it works?

The logic is the same as in #3526. ContentService.getMultipleContent (CP branch) memoizes "list entries + fetch each entry" per process:

  • Key: (accountName, storeId, contentType, locale). The page slug stays out of the key, so every collection shares one list.
  • In-flight deduplication: concurrent page generations wait on the same promise.
  • TTL of 5 minutes: this bounds staleness in long-lived processes (ISR). A CMS publish already triggers a new build.
  • Preview and branch preview bypass the cache.
  • Failures are not cached: the entry is evicted (only if it is still the failed promise) and the error is re-thrown.

The scroll loop and fillEntriesWithData moved unchanged into a private listAndFillEntries. Template selection and the hCMS path are untouched, and nothing public changes.

Differences from dev

  • 3.x has no OPTIONAL_CONTENT_TYPES, so that hunk of the cherry-pick was dropped.
  • 3.x doesn't pass a locale to the CP client, so the locale part of the key is always undefined. In practice the key is (accountName, storeId, contentType).
  • 3.x runs Jest, so test/server/content/service.test.ts is a Jest port of the Vitest suite, minus the per-locale case.

How to test it?

  • cd packages/core && pnpm jest test/server/content/service.test.ts. It runs 9 tests: concurrent PLPs with different slugs share one list, reuse within the TTL, the direct slug match still wins, scroll pagination, separate keys per content type, preview bypass, failures not cached, a late failure not evicting a newer fetch, and TTL expiry.
  • I checked that the suite catches the bug: run against the unpatched 3.x service.ts, 7 of the 9 tests fail.
  • The full packages/core Jest suite passes locally (119 tests). The one exception is test/server/index.test.ts, which can't load locally without @faststore/api built and @generated/persisted-documents.json. This PR doesn't touch it.

Starters Deploy Preview

N/A (server-side content fetching only)

References

Checklist

  • PR title and commit messages follow the Conventional Commits specification
  • PR description
  • Label: bug / performance

Summary by CodeRabbit

  • Performance

    • Content Platform list results are now cached for five minutes to reduce repeated loading.
    • Preview requests continue to fetch fresh results without using the cache.
    • Concurrent and repeated requests are handled more efficiently while preserving pagination behavior.
  • Reliability

    • Failed requests no longer leave unusable cached results, allowing subsequent retries.

…ns (3.x)

Backport of #3526 (b03ed33) to 3.x.

On Content Platform stores, each cold PLP/PDP generation paginates
listEntries and fetches every entry to pick a template, costing
ceil(N / 20) + N CP calls per page. getMultipleContent now memoizes
"list entries + fetch each entry" per (accountName, storeId,
contentType, locale), with in-flight deduplication and a 5-minute TTL.
Previews bypass the cache, and failures are not cached.

Differences from dev:
- 3.x has no OPTIONAL_CONTENT_TYPES; that hunk was dropped.
- 3.x passes no locale to the CP client, so the locale part of the key
  is always undefined.
- The tests are ported from Vitest to Jest, without the per-locale case.

Co-authored-by: Cursor <[email protected]>
@lemagnetic
lemagnetic requested a review from a team as a code owner October 21, 2026 17:08
@lemagnetic
lemagnetic requested review from eduardoformiga and hellofanny and removed request for a team October 21, 2026 17:08
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: vtex/faststore/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: a48aab7a-0e5f-4301-aeb9-2c54c2543a65
📥 Commits

Reviewing files that changed from the base of the PR and between 31df583 and 6480dd5.

📒 Files selected for processing: 2
  • packages/core/src/server/content/service.ts
  • packages/core/test/server/content/service.test.ts

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Walkthrough

ContentService now caches non-preview Content Platform list results for five minutes by account, store, content type, and locale. Preview requests bypass the cache. List pagination and entry enrichment use a shared method, with tests covering caching, pagination, and failure handling.

Changes

Content list caching

Layer / File(s) Summary
List pagination and enrichment
packages/core/src/server/content/service.ts, packages/core/test/server/content/service.test.ts
listAndFillEntries handles pagination and entry enrichment. Tests cover paginated list fetching and separate cache entries for different content types.
Cache policy and request handling
packages/core/src/server/content/service.ts, packages/core/test/server/content/service.test.ts
Non-preview lists are cached for five minutes by account, store, content type, and locale. Concurrent requests reuse cached promises. Preview requests bypass the cache. Failed requests remove only their matching cache entry. Tests cover cache reuse, slug lookup precedence, preview bypass, failure handling, and TTL expiration.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: vitorflg

Merge Risk: ⚪ Minimal · up to 6480d

The cache can serve subsequent page requests, and no actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the primary change: caching the Content Platform template list across page generations in the 3.x branch.
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.
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@lemagnetic
lemagnetic merged commit 825c176 into 3.x Oct 26, 2026
12 of 13 checks passed
@lemagnetic
lemagnetic deleted the fix/3.x-cp-plp-template-cache branch October 26, 2026 22:11
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.

2 participants