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

Boost: Ensure delivery method tester is only tested once per network on Multisites #41918

Open
wants to merge 18 commits into
base: trunk
Choose a base branch
from

Conversation

LiamSarsfield
Copy link
Contributor

@LiamSarsfield LiamSarsfield commented Feb 20, 2025

Fixes #41788

Proposed changes:

  • New Network-Wide Cron Management System
    • Added new Scheduled_Event class to handle network-wide cron jobs.
    • Ensures cron jobs run only once per network instead of per site.
    • Compatible with both multisite and single-site installations.
  • Legacy System Migration
    • Unscheduled legacy cronjob names:
      • jetpack_boost_minify_cron_cache_cleanup
      • jetpack_boost_404_tester_cron
    • Migrated to new network-aware scheduling system
  • Code Organization
    • Moved minify legacy notice logic from wp-js-data-sync.php to Minify class
    • Added proper unit tests for all new scheduling functionality

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

N/A

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

N/A

Testing instructions:

I'll write detailed testing instructions focusing on verifying both the migration and multisite functionality.

Testing Instructions

Prerequisites

  • Install WP Crontrol plugin for cron job verification
  • Have access to both a single-site and multisite WordPress installation
  • Ensure Jetpack Boost is installed and the Minify feature was previously active

1. Migration Testing

Verify Legacy Cron Migration

  1. Before Update/Branch/PR

    • Open WP Crontrol (Tools → Cron Events)
    • Note down any existing cron jobs with these names:
      • jetpack_boost_minify_cron_cache_cleanup
      • jetpack_boost_404_tester_cron
    • Take a screenshot for comparison if needed
  2. Apply Update/Branch/PR

    • Install/update to this version of Jetpack Boost
    • It's important that the update method also changes the version number of the plugin
  3. Verify Migration

    • Check WP Crontrol again
    • Confirm the old cron jobs are no longer present
    • Verify new network cron jobs exist:
      • Look for jetpack_boost_network_cron events
      • They should have arguments containing either:
        • ['jetpack_boost_minify_cron_cache_cleanup', []]
        • ['jetpack_boost_404_tester_cron', []]

2. Multisite Testing

Network Admin Testing

  1. Network Admin View

    • Log in as Network Administrator
    • Go to Network Admin → Jetpack Boost
    • Retoggle a Minify feature
    • Check WP Crontrol again
    • Confirm the old cron jobs are no longer present
    • Verify new network cron jobs exist:
      • Look for jetpack_boost_network_cron events
      • They should have arguments containing either:
        • ['jetpack_boost_minify_cron_cache_cleanup', []]
        • ['jetpack_boost_404_tester_cron', []]
  2. Individual Site Admin Testing

    • Log in as a regular site administrator
    • Go to individual site's Jetpack Boost settings
    • Retoggle a Minify feature
    • Check WP Crontrol again
    • Confirm the old cron jobs are no longer present
    • Verify new network cron jobs exist:
      • Look for jetpack_boost_network_cron events
      • They should have arguments containing either:
        • ['jetpack_boost_minify_cron_cache_cleanup', []]
        • ['jetpack_boost_404_tester_cron', []]

Cron Execution Testing

  1. Initial Setup

    • Create at least 3 subsites in your multisite installation
    • Enable Jetpack Boost on each site
    • Enable Minify feature on each site
  2. Monitor Cron Execution

    • In WP Crontrol, observe the jetpack_boost_network_cron events
    • Note the next scheduled run time
    • Use WP Crontrol to manually trigger the cron event
    • Check site options in the database:
      SELECT * FROM wp_sitemeta WHERE 
      meta_key LIKE '%network_cron_ran%' OR 
      meta_key LIKE '%network_cron_recurrence%';
    • Verify only one entry exists per cron job type, not per site
  3. Cross-Site Verification

    • Enable Debug logging
    • Add this to wp-config.php:
      define('WP_DEBUG', true);
      define('WP_DEBUG_LOG', true);
    • Monitor debug.log while cron jobs execute
    • Verify the task runs only once, not per subsite
  4. Recovery Testing

    • Manually delete cron jobs using WP Crontrol
    • Retoggle all Minify features to off, and then back on
    • Verify cron jobs are properly rescheduled

Notes

  • If testing in a development environment, you may need to trigger cron jobs manually as WordPress cron requires site visits to trigger
  • Some operations may need to wait for the scheduled time - use WP Crontrol to trigger them manually for immediate testing
  • Keep an eye on the debug.log for any unexpected behaviors or errors

- Add `jetpack_boost_execute_network_cron()` to schedule singleton network-wide cron jobs
- Implement `jetpack_boost_schedule_singleton_network_cron()` to ensure unique cron job scheduling
- Update 404 tester cron job scheduling to use new network-wide cron method
Copy link
Contributor

github-actions bot commented Feb 20, 2025

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.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


Boost plugin:

  • Next scheduled release: March 3, 2025.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added [Plugin] Boost A feature to speed up the site and improve performance. [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Feb 20, 2025
@LiamSarsfield LiamSarsfield changed the title Boost/update/404-tester-multisite-check Boost: Make sure multisites only check concatenation 404 status/GC once a day Feb 20, 2025
@LiamSarsfield LiamSarsfield changed the title Boost: Make sure multisites only check concatenation 404 status/GC once a day Boost: Ensure delivery method tester is only tested once per network on Multisites Feb 20, 2025
- Add multisite check to prevent legacy notice for non-network admins
- Refactor cron job scheduling for 404 tester and cache cleanup
- Simplify network-wide cron job scheduling logic
@LiamSarsfield LiamSarsfield added [Boost Feature] Minify [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Feb 20, 2025
@LiamSarsfield LiamSarsfield removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Feb 20, 2025
@LiamSarsfield LiamSarsfield added this to the boost/3.10.0 milestone Feb 20, 2025
@LiamSarsfield LiamSarsfield self-assigned this Feb 20, 2025
Copy link

jp-launch-control bot commented Feb 20, 2025

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/plugins/boost/app/modules/optimizations/minify/Minify.php 0/20 (0.00%) 0.00% 13 💔
projects/plugins/boost/app/class-jetpack-boost.php 0/90 (0.00%) 0.00% 3 ❤️‍🩹
projects/plugins/boost/app/lib/minify/functions-helpers.php 0/129 (0.00%) 0.00% -1 💚
projects/plugins/boost/wp-js-data-sync.php 0/49 (0.00%) 0.00% -11 💚

1 file is newly checked for coverage.

File Coverage
projects/plugins/boost/app/lib/Scheduled_Event.php 32/32 (100.00%) 💚

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

- Refactor legacy notice logic from wp-js-data-sync.php to Minify.php
- Implement Has_Data_Sync interface for Minify module
- Register readonly data sync entry for minify legacy notice
- Add static method to determine legacy notice visibility
- Modify `jetpack_boost_execute_network_cron()` to dynamically retrieve cron recurrence
- Update `jetpack_boost_schedule_singleton_network_cron()` to save recurrence as a site option
- Add `jetpack_boost_unschedule_singleton_network_cron()` to clean up network cron jobs
- Adjust action hook parameters for network cron scheduling
- Add TODO comment for future code organization
- Move network cron job scheduling and unscheduling logic to a new Scheduled_Event class
- Remove legacy cron job scheduling functions from minify helpers
- Update Jetpack Boost main class to add Scheduled_Event to setup
- Unschedule legacy cronjob names during plugin activation
- Remove unnecessary action hooks and inline cron job functions
- Update Scheduled_Event class documentation to reference the correct method name
- Replace legacy function calls with Scheduled_Event::schedule_singleton_network_cron()
- Add missing action hook for 404 tester cron job
- Update `schedule_singleton_network_cron()` to use a consistent network cron hook
- Modify hook parameters to include original hook and arguments
- Ensure proper tracking of network-wide cron job scheduling
- Update `schedule_singleton_network_cron()` to return a boolean indicating scheduling status
- Modify 404 tester cron job scheduling to use the updated method
- Simplify cron job scheduling logic in page optimize helpers
- Create comprehensive test suite for Scheduled_Event class
- Test network cron job scheduling, execution, and unscheduling methods
- Verify behavior for different cron job scenarios using Brain Monkey
@LiamSarsfield LiamSarsfield added the I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. label Feb 21, 2025
…ertions

- Modify test methods to use `expectNotToPerformAssertions()`
- Remove unnecessary return value checks in test cases
- Simplify test assertions for network cron job methods
- Add workaround to handle WordPress converting empty arrays to strings for actions
- Ensure actions with no arguments are called correctly using `do_action()`
- Preserve original action call behavior for non-empty argument lists
- Add methods to track and manage blogs subscribed to network cron jobs
- Implement `subscribe_to_network_cron()` to record blog participation
- Create `unsubscribe_from_network_cron()` to manage blog subscriptions
- Modify unscheduling logic to clean up network cron options only when no blogs are subscribed
- Add test expectations for tracking blog subscriptions in network cron jobs
- Implement checks for getting, updating, and deleting blog subscription site options
- Enhance test coverage for network cron job subscription management
- Add type checking for `$file_age` parameter in cache cleanup functions
- Ensure consistent default value when non-integer values are passed
- Prevent potential type-related issues during cache cleanup
@LiamSarsfield LiamSarsfield requested a review from a team February 21, 2025 17:42
@LiamSarsfield LiamSarsfield added [Status] Needs Team Review Your teammate needs to review this PR. and removed [Status] In Progress labels Feb 21, 2025
@LiamSarsfield LiamSarsfield marked this pull request as ready for review February 21, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Boost Feature] Minify I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Plugin] Boost A feature to speed up the site and improve performance. [Status] In Progress [Status] Needs Team Review Your teammate needs to review this PR. [Tests] Includes Tests [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.

Boost: Make sure multisites only check concatenation 404 status/GC once a day
1 participant