-
Notifications
You must be signed in to change notification settings - Fork 54
Refactor sync-support.ts #2359
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
Refactor sync-support.ts #2359
Conversation
| if ( ! site.capabilities?.manage_options ) { | ||
| return 'missing-permissions'; | ||
| } | ||
| if ( isJetpackSite( site ) ) { |
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.
Why jetpack site is unsupported?
Jetpack is required. So I renamed to isUnsupported.
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.
Similar as in my previous comment:
As far as I remember, we used this in the past to filter out self-hosted sites that are not hosted by us (via WPCOM and Pressable).
In that logic, "Jetpack site" referred to "self-hosted WordPress site".
| } | ||
|
|
||
| export function isJetpackSite( site: SitesEndpointSite ): boolean { | ||
| return !! site.jetpack && ! isAtomicSite( site ) && ! isPressableSite( site ); |
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.
Why detection of jetpack includes ! isAtomic && ! isPressable? Theoretically !! site.jetpack should be enough.
I took a look at history and now the function directly says that jetpack site, which is not atomic is unsupported, and the example is jurasic.ninja
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.
Why detection of jetpack includes ! isAtomic && ! isPressable?
As far as I remember, we used this in the past to filter out self-hosted sites that are not hosted by us (via WPCOM and Pressable).
In that logic, "Jetpack site" referred to "self-hosted WordPress site".
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.
The main point here - below we have a condition that Jetpack sites are unsupported:
if ( isJetpackSite( site ) ) {
return 'unsupported';
}
But it's not true, since all supported sites must have Jetpack. I worked around this code, needed cases to reproduce it, and got stuck.
In that logic, "Jetpack site" referred to "self-hosted WordPress site".
Then it should be either isUnsupported or isSelfHosted, but not isJetpackSite.
| } | ||
|
|
||
| export function needsTransfer( site: SitesEndpointSite ): boolean { | ||
| return ! isJetpackSite( site ) && ! isPressableSite( site ) && ! isAtomicSite( site ); |
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.
If we read this condition, it says:
- NOT
!! site.jetpack && ! isAtomicSite( site ) && ! isPressableSite( site )
&& && ! isPressableSite( site ) && ! isAtomicSite( site )
It's dificult to undersathnd when it's actually true. I have read the history of comits and simplified to just ! site.jetpack && ! isAtomicSite( site ). And added the comment to how to reproduce the case.
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.
I think this was a workaround to check for a Simple site (a site that is not Jetpack, not Atomic and not Pressable).
It was as long time again since I looked at the old logic, but I believe there was some edge case that resulted in this more complex check.
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.
The main point here, that the condition is - ! ( !! site.jetpack && ! isAtomicSite( site ) && ! isPressableSite( site ) ) && ! isPressableSite( site ) && ! isAtomicSite( site ), and it's not possible to understand it. And I haven't found any use case for something like this. Also reading commits history - I haven't found any "Testing instruction" or some PR description which says about some unusual use case.
| if ( isUnsupported( site ) && ! isPressableSite( site ) ) { | ||
| return 'unsupported'; | ||
| } | ||
| if ( ! hasSupportedPlan( site ) && ! isPressableSite( site ) ) { |
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.
In this condition we keep isPressableSite here, outside the hasSupportedPlan and imo it's good idea, to be clear at the upper level that the plan is about only dotcom, and it's not about Pressable.
So I added the same approach to two other cases (isUnsupported and needsTransfer).
Also, it's for consistency.
📊 Performance Test ResultsComparing 33366f8 vs trunk site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change |
ivan-ottinger
left a comment
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 for the improvements, Vova. This logic is indeed difficult to troubleshoot.
So far the changes look generally good to me and I haven't noticed any regressions so far. I have left a couple of comments.
Tomorrow I will give this a second look with fresh 🧠 . 🙂
| } | ||
|
|
||
| export function isJetpackSite( site: SitesEndpointSite ): boolean { | ||
| return !! site.jetpack && ! isAtomicSite( site ) && ! isPressableSite( site ); |
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.
Why detection of jetpack includes ! isAtomic && ! isPressable?
As far as I remember, we used this in the past to filter out self-hosted sites that are not hosted by us (via WPCOM and Pressable).
In that logic, "Jetpack site" referred to "self-hosted WordPress site".
| } | ||
|
|
||
| export function needsTransfer( site: SitesEndpointSite ): boolean { | ||
| return ! isJetpackSite( site ) && ! isPressableSite( site ) && ! isAtomicSite( site ); |
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.
I think this was a workaround to check for a Simple site (a site that is not Jetpack, not Atomic and not Pressable).
It was as long time again since I looked at the old logic, but I believe there was some edge case that resulted in this more complex check.
|
|
||
| export function isJetpackSite( site: SitesEndpointSite ): boolean { | ||
| return !! site.jetpack && ! isAtomicSite( site ) && ! isPressableSite( site ); | ||
| // Sites hosted outside wp.com and Pressable (e.g. jurassic.ninja). |
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.
While reviewing the code I wanted to suggest moving isPressableSite check into the isUnsupported helper function directly, but then I read your other comment below:
In this condition we keep isPressableSite here, outside the hasSupportedPlan and imo it's good idea, to be clear at the upper level that the plan is about only dotcom, and it's not about Pressable.
So I added the same approach to two other cases (isUnsupported and needsTransfer).
Also, it's for consistency.
Sounds good to me. 👍🏼 With that I think we may want to update the comment above:
// Sites hosted outside wp.com and Pressable (e.g. jurassic.ninja).
As now it looks as if isUnsupported also checks for Pressable sites.
| if ( ! site.capabilities?.manage_options ) { | ||
| return 'missing-permissions'; | ||
| } | ||
| if ( isJetpackSite( site ) ) { |
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.
Similar as in my previous comment:
As far as I remember, we used this in the past to filter out self-hosted sites that are not hosted by us (via WPCOM and Pressable).
In that logic, "Jetpack site" referred to "self-hosted WordPress site".
ivan-ottinger
left a comment
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 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.
I just wanted to approve this but it looks like it is already merged. The changes looked good to me, I did not see any regressions in the Connect your site modal.


Proposed Changes
I worked around the sync-support module and didn't get how to reproduce cases, since the conditions are not clear.
See comments.
Testing Instructions
Assert that everything still works well: