Skip to content
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

Sync: add a new method, do_only_first_initial_sync #21676

Merged
merged 12 commits into from
Nov 12, 2021

Conversation

kbrown9
Copy link
Member

@kbrown9 kbrown9 commented Nov 9, 2021

Changes proposed in this Pull Request:

  • Add a new method, do_only_first_initial_sync, which is used to trigger an initial full sync only when one hasn't already been performed.
  • This method will be useful for plugins that want to run an initial full sync on sites that haven't already had an initial sync.

Jetpack product discussion

  • n/a

Does this pull request change what data or activity we track or use?

  • no

Testing instructions:

  1. Install and activate this branch.
  2. Connect to WPCOM.
  3. Check that the full sync status option is populated with data. The started and finished values should be timestamps. wp option get jetpack_sync_full_status
  4. Using wp shell, try to start an initial sync as shown below. This should return false because an initial sync has already been run.
    return Automattic\Jetpack\Sync\Actions::do_only_first_initial_sync();
  5. Clear the jetpack_sync_full_status option: wp option delete jetpack_sync_full_status
  6. Using wp shell, try to start an initial sync. This should return null because the full sync was started.
    return Automattic\Jetpack\Sync\Actions::do_only_first_initial_sync();

Do not run an initial sync when these two conditions are true:
 - The site is not registering.
 - An initial sync has been run before.

This change will allow plugins to run an initial sync outside of the site
registration process. For example, if a plugin starts using sync after an update,
it can run an initial sync to get the cache site up to date. However, this isn't
necessary if another plugin has already run an initial sync.
@kbrown9 kbrown9 added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress [Package] Sync labels Nov 9, 2021
@kbrown9 kbrown9 self-assigned this Nov 9, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 30, 2021.

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Nov 9, 2021
@kbrown9 kbrown9 force-pushed the update/add_method_for_initial_sync_check branch from 115d369 to cb73696 Compare November 10, 2021 03:38
@kbrown9 kbrown9 requested review from htdat and mdbitz November 10, 2021 03:45
@kbrown9 kbrown9 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels Nov 10, 2021
Copy link
Contributor

@mdbitz mdbitz left a comment

Choose a reason for hiding this comment

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

Question on the additional action/is_started check

}

// Don't start a new sync if the site isn't registering and an initial sync was already started.
if ( ! doing_action( 'jetpack_site_registered' ) && $full_sync_module->is_started() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kbrown9 can you outline why this check on 'jetpack_site_registered' is added? Logically it does make sense but it is a departure from existing functionality where the action 'jetpack_user_authorized' can also trigger do_initial_sync.

Also won't this check on is_started cause issues with sites that delete Jetpack than re-install?

Would it make sense to add flag of $strict or similar that would preserve existing flow and then add this if statement only if strict is true? This way WC Pay can call do_initial_sync( true ) and get the flow they want but not change existing flows?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like your proposal to add a flag. I think an even better approach would be to introduce a new method, Actions::do_only_first_initial_sync, which consumer plugins could call when they want an initial sync run only when one has never been run before.

The Actions::do_intial_sync method is hooked to a few actions, and the jetpack_site_registered action passes a few arguments to the callback functions. We specify that Actions::do_initial_sync accepts 0 arguments from the action hook here, but if that ever needed to change, I think we would run into problems.

I think introducing the new Actions::do_only_first_initial_sync method will be both clearer and safer than adding a flag to the existing Actions::do_intial_sync method. What do you think of this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree a new method is cleaner and safer for usage. 👍 from me on this approach

@github-actions github-actions bot added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Nov 12, 2021
@kbrown9 kbrown9 changed the title Sync: do not run an initial sync if an initial sync has already been run Sync: add a new method, do_only_first_initial_sync Nov 12, 2021
@kbrown9 kbrown9 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Nov 12, 2021
Copy link
Contributor

@mdbitz mdbitz left a comment

Choose a reason for hiding this comment

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

Thanks for the great test instructions. Verified and now Approving.

@kbrown9 kbrown9 merged commit 8167609 into master Nov 12, 2021
@kbrown9 kbrown9 deleted the update/add_method_for_initial_sync_check branch November 12, 2021 20:17
@github-actions github-actions bot added this to the jetpack/10.4 milestone Nov 12, 2021
@github-actions github-actions bot removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Nov 12, 2021
davidlonjon added a commit that referenced this pull request Nov 16, 2021
* master: (22 commits)
  VideoPress: reload block on rating change (#21653)
  Assets: Changelog for package version 1.12.0 (#21744)
  assets: Add `wp_register_script` wrapper (and then use it everywhere) (#21689)
  eslint-config-target-es: Configure mirror repo (#21731)
  Use monorepo `validate-es` script to validate Webpack builds (#21729)
  Backup: Replace daily backup references/upsell links with new real-time products (#21715)
  Likes: reimplement non-admin portions without jQuery (#21726)
  Autoloader: Not activated autoload queue is false (#21517)
  Sync: add a new method, do_only_first_initial_sync (#21676)
  webpack-config: Configure minifier to preserve translator comments (#21667)
  webpack-config: Use `@automattic/babel-plugin-preserve-i18n` (#21700)
  Create eslint-config-target-es JS package (#21660)
  webpack-config: Fork calypso-build's mini-css-with-rtl plugin (#21595)
  Allow /sites/${site}/external-media/copy/pexels to insert post meta data  (#21659)
  jetpack: Don't set Webpack's `output.pathinfo` in production builds (#21727)
  Boost: Implement support for loading stylesheets when JavaScript is disabled in the context Critical CSS being enabled (#21713)
  RNA: export the Connection store (#21388)
  Display notice when user has unactivated product license keys (#21474)
  Gardening: ensure it can use Composer (#21712)
  Nav Unification: Display the stats sparkline on WP Admin for Atomic sites (#21655)
  ...
davidlonjon added a commit that referenced this pull request Nov 16, 2021
* master:
  VideoPress: reload block on rating change (#21653)
  Assets: Changelog for package version 1.12.0 (#21744)
  assets: Add `wp_register_script` wrapper (and then use it everywhere) (#21689)
  eslint-config-target-es: Configure mirror repo (#21731)
  Use monorepo `validate-es` script to validate Webpack builds (#21729)
  Backup: Replace daily backup references/upsell links with new real-time products (#21715)
  Likes: reimplement non-admin portions without jQuery (#21726)
  Autoloader: Not activated autoload queue is false (#21517)
  Sync: add a new method, do_only_first_initial_sync (#21676)
  webpack-config: Configure minifier to preserve translator comments (#21667)
  webpack-config: Use `@automattic/babel-plugin-preserve-i18n` (#21700)
  Create eslint-config-target-es JS package (#21660)
  webpack-config: Fork calypso-build's mini-css-with-rtl plugin (#21595)
  Allow /sites/${site}/external-media/copy/pexels to insert post meta data  (#21659)
  jetpack: Don't set Webpack's `output.pathinfo` in production builds (#21727)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Sync [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants