-
Notifications
You must be signed in to change notification settings - Fork 317
feat(docs): add gzip compression to docs-ledger publish requests #16033
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
Draft
broady
wants to merge
6
commits into
feat/docs_ledger
Choose a base branch
from
devin/1779332916-ledger-gzip-compression
base: feat/docs_ledger
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
02cd8a3
feat(fdr): add gzip compression to docs-ledger publish requests
devin-ai-integration[bot] 0910dfe
fix: sort imports to satisfy biome lint
devin-ai-integration[bot] b4d2120
refactor: use oRPC client with custom gzip fetch instead of raw fetch…
devin-ai-integration[bot] 69d0414
refactor: use streaming CompressionStream for gzip fetch
devin-ai-integration[bot] a118943
feat(cli): add gzip compression to v2 docs publish requests
devin-ai-integration[bot] 6605a3a
refactor: consolidate compressedLedgerFetch into compressedFetch
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/cli/cli/changes/unreleased/feat-ledger-gzip-compression.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| - summary: | | ||
| Gzip-compress docs-ledger register and finish request bodies to reduce | ||
| transfer time for large multi-locale deployments. | ||
| type: feat |
5 changes: 5 additions & 0 deletions
5
packages/cli/cli/changes/unreleased/feat-v2-gzip-compression.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| - summary: | | ||
| Gzip-compress v2 docs publish request bodies (register, finish, API | ||
| registration, translation registration) to reduce transfer time for | ||
| large deployments. | ||
| type: feat |
48 changes: 48 additions & 0 deletions
48
packages/cli/generation/remote-generation/remote-workspace-runner/src/compressedFetch.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Returns a `fetch` function that gzip-compresses request bodies using the | ||
| * Web Streams `CompressionStream` API. | ||
| * | ||
| * Designed to be captured by oRPC's `LinkFetchClient` at construction time | ||
| * so all subsequent requests through the client are transparently compressed. | ||
| * | ||
| * The FDR server registers `@fastify/compress` which transparently | ||
| * decompresses incoming `Content-Encoding: gzip` request bodies. | ||
| */ | ||
| export function createGzipFetch(): typeof globalThis.fetch { | ||
| return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => { | ||
| if (input instanceof Request && input.body != null) { | ||
| const headers = new Headers(input.headers); | ||
| headers.set("Content-Encoding", "gzip"); | ||
| headers.delete("Content-Length"); | ||
|
|
||
| const compressedBody = input.body.pipeThrough(new CompressionStream("gzip")); | ||
|
|
||
| const compressedRequest = new Request(input.url, { | ||
| method: input.method, | ||
| headers, | ||
| body: compressedBody, | ||
| // @ts-expect-error duplex required for streaming request bodies in Node.js | ||
| duplex: "half" | ||
| }); | ||
| return globalThis.fetch(compressedRequest, init); | ||
| } | ||
|
|
||
| return globalThis.fetch(input, init); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Gzip-compresses a JSON body and returns a `RequestInit` suitable for | ||
| * `fetch()`, with the correct `Content-Encoding` and `Content-Type` headers. | ||
| */ | ||
| export async function gzipJsonBody(body: unknown): Promise<{ body: ReadableStream; headers: Record<string, string> }> { | ||
| const json = JSON.stringify(body); | ||
| const stream = new Blob([json]).stream().pipeThrough(new CompressionStream("gzip")); | ||
| return { | ||
| body: stream, | ||
| headers: { | ||
| "Content-Encoding": "gzip", | ||
| "Content-Type": "application/json" | ||
| } | ||
| }; | ||
| } |
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
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
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
Oops, something went wrong.
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.
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.
Critical: Global state corruption on error
If
createFdrService()throws an exception,globalThis.fetchwill remain permanently modified to the gzip-compressing version, affecting all subsequent fetch calls in the process. This will cause subsequent non-compressed endpoints to receive gzipped data they don't expect.Fix: Wrap in try/finally:
Spotted by Graphite

Is this helpful? React 👍 or 👎 to let us know.