Repository navigation
fix(content): read the Library export's pages in bounded calls, and wrap Excel's page text - #1365
Merged
Merged
Conversation
…rap Excel's page text Follow-up to ansvisor#1354's review. getContentDraftPages took up to 500 ids and sent every page back in one response. It now takes at most 50 a call (DRAFT_PAGES_PER_CALL) and stops at about 3 MB of pages, handing back the ids it left, always with at least one page; the Library reads a list in turn, each call's rest first. Excel's Content cell wraps, as the opportunity export's does. getContentDraftPages has its own test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
@gkhngyk the follow-up to your #1354 review (items 1–3).
|
gkhngyk
approved these changes
Oct 22, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good. One small follow-up:
- The response budget counts characters, not bytes (
web/src/lib/actions/content-drafts.ts:297).pageSizeadds up.length, which counts UTF-16 characters. The 4.5 MB response limit counts bytes.- A page in Cyrillic, Greek or Arabic takes about 2 bytes a character in UTF-8, and CJK takes 3. The serialized response also escapes every
"in the HTML. - So 50 non-Latin pages can reach 3,000,000 characters, which is 6–9 MB, before the budget stops them.
- Fix: count bytes with
Buffer.byteLength(...)for the body, title and URL (the action runs on Node), or halve the budget. The budget test still passes with its ASCII bodies.
Checked and fine:
- The read goes through the session client.
content_drafts: member selectlimits it to the caller's brands, and.eq('brand_id', …)keeps it to the brand given. - 50 uuids add about 1.9 KB to the request URL, and the primary-key lookup is far inside the 8 s timeout.
- The client's queue keeps the list's order:
restgoes first, and the items are built indraftsorder. Each call returns at least one page or moves past the missing ids, so the loop always ends. - If one call fails, the error reaches the existing toast and no file is written.
- Excel's
{ value, wrap: true }cell is the same formopportunityWorkbookuses, and the cut is applied before the wrap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1354's review: Library Export now reads drafts' pages in bounded calls, Excel wraps the page text, and
getContentDraftPageshas its own test.getContentDraftPagesreturned every page of up to 500 drafts in one server-action response. A page averages ~30 KB on prod and can reach 500 KB.DRAFT_PAGES_PER_CALL= 50 ids. The constant lives inlib/content/drafts.ts, since a'use server'file exports only async functions..eq('brand_id', …).in('id', …)).PAGES_RESPONSE_BUDGET, well inside a serverless response's 4.5 MB). It returns{ pages, rest }, whererestholds the ids it left for the next call. It always returns at least one page, so a list keeps moving._library-export.tsxreads the list in turn: 50 ids a call, with each call'srestgoing first in the next. The single-row export reads its one page as before.{ value, wrap: true }when it has a line break, asopportunityWorkbookdoes. The 32,767-character cut still applies first. A full page makes Excel size its row up to the 409 pt maximum. That is the trade-off for readable lines.lib/actions/content-drafts-pages.test.ts:brand_id;invalid;draft-export.test.ts: the wrapped Content cell, and the cut on itsvalue.page.test.tsx: 120 drafts are read as 50 / 50 / 20, in order, with every draft in the CSV once. A call that leaves 20 ids for its size makes the next call start with those 20.Deploy note: a browser tab still on the old client during the deploy may send up to 500 ids, get
invalidand show the export-failed toast until it reloads.Related issue
Follow-up to #1354 (review items 1–3). No issue.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) (0 errors; the 6 warnings are in untouched files, as on main)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run: web
yarn test(2,769 tests) andyarn build.🤖 Generated with Claude Code