Skip to content

Boost: Add cleanup for expired concatenated file paths #44134

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

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

Conversation

dilirity
Copy link
Member

@dilirity dilirity commented Jun 30, 2025

Fixes HOG-189

Proposed changes:

  • Set expiry of concatenated options to 1 week (was previously 1 year);
  • Add cleanup for concatenated options that have expired.

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

HOG-189

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

no

Testing instructions:

Pre-requisites

  • Add this snippet to your site, to create some concatenated paths. Two of the file paths have expired so they should get deleted after cleanup runs:
add_action( 'template_redirect', function () {
	if ( ! isset( $_GET['jb-test-concat-cleanup'] ) ) {
		return;
	}

	$option_prefix = 'jb_transient_concat_paths_';

	for ( $i = 1; $i <= 6; $i++ ) {
		$option_name = $option_prefix . $i;
		$expire = time();

		// Make options 3+ (inclusive), expire later.
		if ( $i >= 3 ) {
			$expire += MONTH_IN_SECONDS;
		}

		$option_value = array(
			'expire' => $expire,
			'data' => array(
				'paths' => array(
					'script-path-1.js',
					'script-path-2.js',
				),
			),
		);

		update_option( $option_name, $option_value );
	}
} );
  • Open your home page with the get param jb-test-concat-cleanup to trigger the script;
  • Check the database for options with name LIKE jb_transient_c (or run this SQL query SELECT * FROM wp_optionsWHEREoption_name LIKE '%jb_transient_c%'. There should be 6 file path Boost transients:
CleanShot 2025-06-30 at 14 26 00@2x

Test that cleanup works

  • Setup Boost (free) from this branch;
  • Open WP Admin -> Tools -> Cron Events and search for clean to make sure that jetpack_boost_minify_cron_cleanup_concat_paths and jetpack_boost_minify_cron_cleanup_concat_paths_followup are not in the list;
  • Enable Concatenate JS (or Concatenate CSS);
  • Check Tools -> Cron Events again and there should be an event called jetpack_boost_minify_cron_cleanup_concat_paths;
  • Hover over the event, and click Run Now (to force schedule to run cleanup);
  • Since WP schedules need a visit to the website, open the home page after you run the script (this will simulate a user/bot visit to the website);
  • Now check the entries in the DB with the query from the Pre-Requisites section and entries 1 and 2 should be gone (you might see other entries, but that's probably because the home page visit concatenated some assets):
CleanShot 2025-06-30 at 14 29 49@2x

Test that cleanup schedules are removed

  • Disable both Concatenate JS and Concatenate CSS;
  • Visit Tools -> Cron Events and search for clean to make sure that jetpack_boost_minify_cron_cleanup_concat_paths and jetpack_boost_minify_cron_cleanup_concat_paths_followup are not in the list;
  • Uninstalling Boost with either Concatenate JS or Concatenate CSS active should remove the schedules up as well.

@dilirity dilirity self-assigned this Jun 30, 2025
@dilirity dilirity changed the title Add cleanup for expired concatenated file paths Boost: Add cleanup for expired concatenated file paths Jun 30, 2025
@github-actions github-actions bot added [Plugin] Boost A feature to speed up the site and improve performance. [Status] In Progress labels Jun 30, 2025
Copy link
Contributor

github-actions bot commented Jun 30, 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 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 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Boost plugin:

No scheduled milestone found for this plugin.

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

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 30, 2025
Copy link

jp-launch-control bot commented Jun 30, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/boost/app/lib/minify/functions-helpers.php 0/143 (0.00%) 0.00% 3 ❤️‍🩹

1 file is newly checked for coverage.

File Coverage
projects/plugins/boost/app/lib/minify/class-cleanup-stored-paths.php 0/40 (0.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. .

@dilirity dilirity added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels Jun 30, 2025
@dilirity dilirity marked this pull request as ready for review June 30, 2025 11:33
@dilirity dilirity added I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. and removed [Status] In Progress labels Jun 30, 2025
@dilirity dilirity added DO NOT MERGE don't merge it! and removed [Status] In Progress labels Jun 30, 2025
@dilirity dilirity removed the DO NOT MERGE don't merge it! label Jun 30, 2025
@LiamSarsfield
Copy link
Contributor

LGTM besides the 2 comments, and works as expected once these are addressed. The suggestion code should also be updated to use $expire = time(); instead of $expire = time() + ( $i * DAY_IN_SECONDS )

dilirity and others added 3 commits July 1, 2025 18:38
It makes more sense for the option name to be a generic jetpack boost option, instead of a transient (which might be confusing).

Co-authored-by: Liam Sarsfield <43409125+LiamSarsfield@users.noreply.github.com>
@dilirity dilirity requested a review from LiamSarsfield July 1, 2025 15:59
@dilirity
Copy link
Member Author

dilirity commented Jul 1, 2025

@LiamSarsfield thanks for the awesome idea with the offset!

I've implemented the change in 9598f32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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] Needs Review This PR is ready for review. [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