Skip to content

Execute /studio-app/sync/import network request from node process - #1972

Merged
fredrikekelund merged 3 commits into
trunkfrom
f26d/sync-push-from-node-process
Nov 3, 2025
Merged

Execute /studio-app/sync/import network request from node process#1972
fredrikekelund merged 3 commits into
trunkfrom
f26d/sync-push-from-node-process

Conversation

@fredrikekelund

@fredrikekelund fredrikekelund commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

Previously, the /sites/${ remoteSiteId }/studio-app/sync/import API request was made from the renderer process. This required the entire site archive to be stored in the renderer process's memory. This isn't necessary, and it's much more efficient (especially for large archives) to stream the file contents from disk instead. This PR implements a pushArchive IPC handler that does just that.

Testing Instructions

  1. Have a Studio site connected to a remote site
  2. Try the push functionality with a few different configurations (all files/some files/with db/without) and verify that it works as expected

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@fredrikekelund
fredrikekelund requested a review from a team October 30, 2025 07:58
@fredrikekelund fredrikekelund self-assigned this Oct 30, 2025
Comment thread src/ipc-handlers.ts
return pushArchiveResponseSchema.parse( rawResponse );
}

export function removeTemporaryFile( event: IpcMainInvokeEvent, path: string ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming this function is a secondary function of this PR. I did it because "temporal" seems like a misnomer in this context.

Comment thread src/ipc-handlers.ts
}

export async function exportSiteToPush(
export async function exportSiteForPush(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming this function is also a secondary function of this PR. I did it because I think this clarifies the relationship better between this function and pushArchive.

@github-actions

github-actions Bot commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

📊 Performance Test Results

Comparing 366c3cc vs trunk

site-editor

Metric trunk 366c3cc Diff Change
load 13580.00 ms 11079.00 ms -2501.00 ms 🟢 -18.4%

site-startup

Metric trunk 366c3cc Diff Change
siteCreation 22321.00 ms 23275.00 ms +954.00 ms 🔴 4.3%
siteStartup 6993.00 ms 7011.00 ms +18.00 ms 🔴 0.3%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

@fredrikekelund

Copy link
Copy Markdown
Contributor Author

I ran a quick test with a 767MB archive to compare this branch with the latest stable release. The results show significant promise:

Time v1.6.2 stable this branch
Total 14:42 10:45
Upload 5min 39s
Comment thread src/ipc-handlers.ts
Comment on lines +827 to +833
const parseResult = z.object( { error: z.string() } ).safeParse( error );

if ( parseResult.success ) {
return { success: false, error: parseResult.data.error };
}

return { success: false, error: 'Unknown error' };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPC functions that throw in the node process will also throw in the renderer process. The crux is that the error object thrown by the renderer has a different structure, so the most reliable way to pass data back to the renderer is to simply return.

@fredrikekelund fredrikekelund changed the title Run /studio-app/sync/import from node process Oct 31, 2025

@epeicher epeicher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fredrikekelund for improving this! I have tested the Push with different scenarios using both partial sync and full sync, and they all have worked as expected. LGTM!

I have just left a non-blocking question out of curiosity

Comment thread src/ipc-handlers.ts
}

try {
await wpcom.req.post( {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the response of this either a success or an exception in all cases? I was considering getting the response and check the response.success value from it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wpcom.req throws if the request fails or if the response HTTP status code isn't in the 200-range. Since we also don't care about the response body, I don't think we gain anything by validating it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wpcom.js and wpcom-xhr-request API is a little arcane, but the network requests are ultimately based on superagent, so I looked at the source code to double-check my assumption here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wpcom.req throws if the request fails or if the response HTTP status code isn't in the 200-range. Since we also don't care about the response body, I don't think we gain anything by validating it.

Agreed, thanks for clarifying!

@fredrikekelund
fredrikekelund merged commit c275ed6 into trunk Nov 3, 2025
15 checks passed
@fredrikekelund
fredrikekelund deleted the f26d/sync-push-from-node-process branch November 3, 2025 08:24
wojtekn pushed a commit that referenced this pull request Nov 3, 2025
…1972)

* Run `/studio-app/sync/import` from node process

* Improve error handling
gavande1 added a commit that referenced this pull request Dec 2, 2025
gavande1 added a commit that referenced this pull request Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants