-
Notifications
You must be signed in to change notification settings - Fork 130
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
[Themes] - Theme Dev - Reduce API calls and IO operations triggered from theme reconciliation step #4432
Conversation
Thanks for your contribution! Depending on what you are working on, you may want to request a review from a Shopify team:
|
b07ba60
to
cbbd457
Compare
Coverage report
Test suite run success1889 tests passing in 857 suites. Report generated by 🧪jest coverage report action from 60f895a |
@@ -12,9 +12,11 @@ import type {Checksum, Theme} from '@shopify/cli-kit/node/themes/types' | |||
import type {DevServerContext} from './types.js' | |||
|
|||
export function setupDevServer(theme: Theme, ctx: DevServerContext) { | |||
const watcherPromise = setupInMemoryTemplateWatcher(theme, ctx) | |||
const watcherPromise = setupInMemoryTemplateWatcher(ctx) | |||
const envSetup = ensureThemeEnvironmentSetup(theme, ctx) |
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.
There are currently 3 scenarios in which the theme reconciliation step may modify the local filesystem.
Below are how they are currently handled, and how they would be impacted with these changes.
Case | Current | With This Change |
---|---|---|
Delete file only present on local theme | Call API to check if file exists on remote theme, stop because it doesn't. | Save an API call to delete the file on the remote theme for each changed file |
Download file only present on remote theme | Handled here. Read updated checksums and choose not to trigger an upload | Save an IO call to read for each changed file |
Update file using remote theme value | Handled here. Read updated checksums and choose not to trigger an upload | Save an IO call to read for each changed file |
*Read updated checksums and choose not to trigger an upload -> Changes that come from the remote theme will have matching checksums before and after we call read
, because we update the remote checksum when we write
We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. |
startWatcher
until after theme reconciliation is complete4e86ef6
to
c89a7fc
Compare
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.
Thanks! I think it makes sense to delay the watcher start until the reconciliation is over 👍
files.set(asset.key, buildThemeAsset(asset))
? That will ensure we get stats
in the file when writing it from remote (we were getting it from the watcher's read before).
we could potentially remove the call to check that a file exists, reducing the number of API calls for each time a file is deleted from two (one to check if the file exists and one to delete it) to one. However, this needs further consideration.
Yeah, can't we just make the delete call and ignore the "file not found" error? What would be the downside? 🤔
c89a7fc
to
d9691b8
Compare
Yep! Reached alignment on this PR to simply ignore the I believe one of the drawbacks here would be that we can't distinguish between a This would make it harder to introduce something like retries, but since development theme are meant to be ephemeral, I think that's acceptable. Wouldn't be hard to change in the future if we change our mind. |
[Themes] - Theme Dev - Reduce API calls and IO operations triggered from theme reconciliation step
cbbd457
to
60f895a
Compare
WHY are these changes introduced?
Fixes https://github.com/Shopify/develop-advanced-edits/issues/330
While this PR prevents errors from being surfaced when we delete a local file during the reconciliation step, we're still making a call for each file there to check for its existence. These changes prevent us from making those requests in the first place.
Visual.Studio.Code.-.Git_.Staged.Changes.0.files.Dawn.2.mp4
BENEFITS
local filesystem
changes that come from thereconciliation
stepTRADEOFFS
WHAT is this pull request doing?
Defers initialization of the theme watcher until after the reconciliation step has completed. This will prevent the service from trying to synchronize files changes that are coming from the reconciliation step, saving an additional API call each time.
How to test your changes?
Example:
-> Create a development theme
shopify theme delete -d -f && shopify theme push -d
-> Create a file that will only be present on your local theme
-> Initialize command
shopify theme dev --dev-preview --theme-editor-sync --verboes
-> Select
delete files from local theme
-> Note that we are no longer outputting a verbose log with:
File does not exist on remote theme.
Measuring impact
How do we know this change was effective? Please choose one:
Checklist