-
Notifications
You must be signed in to change notification settings - Fork 81
fix: paginate listEntries with scroll #3384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,8 +46,29 @@ export class ContentService { | |
|
|
||
| if (isContentPlatformSource()) { | ||
| const serviceParams = this.convertOptionsToParams(options) | ||
| const { entries } = await this.clientCP.listEntries(serviceParams) | ||
| return this.fillEntriesWithData(entries, serviceParams, options.isPreview) | ||
| // TODO: This should be temporary until the cp data-plane have a search engine. | ||
| const MAX_PAGES = 25 | ||
| const allEntries: ContentEntry[] = [] | ||
| let scroll: string | undefined | ||
| let pages = 0 | ||
|
|
||
| do { | ||
| const result = await this.clientCP.listEntries(serviceParams, scroll) | ||
| allEntries.push(...result.entries) | ||
| const next = result.scroll ?? undefined | ||
| if (next && next === scroll) break | ||
| scroll = next | ||
| } while (scroll && ++pages < MAX_PAGES) | ||
|
|
||
| if (pages >= MAX_PAGES) { | ||
| console.warn('listEntries pagination hit MAX_PAGES cap', serviceParams) | ||
| } | ||
|
|
||
| return this.fillEntriesWithData( | ||
| allEntries, | ||
| serviceParams, | ||
| options.isPreview | ||
| ) | ||
|
Comment on lines
+67
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bound the CP enrichment fan-out before passing all pages downstream. This now turns a single request into 🤖 Prompt for AI Agents |
||
| } | ||
| return getCMSPage(options.cmsOptions) | ||
| } | ||
|
|
@@ -60,6 +81,11 @@ export class ContentService { | |
| const options = this.createContentOptions(plpParams) | ||
|
|
||
| if (isContentPlatformSource()) { | ||
| const directMatch = await this.getSingleContent<PLPContentType>(plpParams) | ||
| if (directMatch) { | ||
| return directMatch | ||
| } | ||
|
|
||
| const pages = (await this.getMultipleContent(plpParams)).data | ||
| if (!pages?.length) throw new MissingContentError(options.cmsOptions) | ||
| return findBestPLPTemplate( | ||
|
|
@@ -79,6 +105,11 @@ export class ContentService { | |
| const options = this.createContentOptions(pdpParams) | ||
|
|
||
| if (isContentPlatformSource()) { | ||
| const directMatch = await this.getSingleContent<PDPContentType>(pdpParams) | ||
| if (directMatch) { | ||
| return directMatch | ||
| } | ||
|
|
||
| const pages = (await this.getMultipleContent(pdpParams)).data | ||
| if (!pages.length) throw new MissingContentError(options.cmsOptions) | ||
| return findBestPDPTemplate( | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't continue with truncated results after the page cap.
If this loop exits with
scrollstill set,allEntriesis incomplete but the code still runs template selection on it. That recreates the original bug for large CP datasets, just at a higher threshold, and can pick the wrong PLP/PDP content.Suggested change
📝 Committable suggestion
🤖 Prompt for AI Agents