Skip to content

Commit 0d859b4

Browse files
committed
Update garbage collection to remove static files as well
1 parent 4897b4f commit 0d859b4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

projects/plugins/boost/app/lib/minify/class-cleanup-stored-paths.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function cleanup_stored_paths_batch() {
9393
}
9494

9595
if ( $value['expire'] <= $expire_timestamp ) {
96+
$this->delete_static_file_by_hash( str_replace( 'jb_transient_concat_paths_', '', $option['option_name'] ) );
9697
delete_option( $option['option_name'] );
9798
}
9899

@@ -104,6 +105,27 @@ public function cleanup_stored_paths_batch() {
104105
return true;
105106
}
106107

108+
/**
109+
* Deletes the static files by hash.
110+
*
111+
* @param string $hash The hash of the file.
112+
* @return void
113+
*/
114+
private function delete_static_file_by_hash( $hash ) {
115+
// Since we don't have a way to know if this file is JS or CSS,
116+
// we delete both.
117+
118+
$js_file_path = jetpack_boost_get_minify_file_path( $hash . '.min.js' );
119+
if ( file_exists( $js_file_path ) ) {
120+
wp_delete_file( $js_file_path );
121+
} else {
122+
$css_file_path = jetpack_boost_get_minify_file_path( $hash . '.min.css' );
123+
if ( file_exists( $css_file_path ) ) {
124+
wp_delete_file( $css_file_path );
125+
}
126+
}
127+
}
128+
107129
/**
108130
* Gets the stored paths to process,
109131
* and skips the ones that were checked in the previous run.

projects/plugins/boost/app/lib/minify/functions-helpers.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ function jetpack_boost_get_minify_url( $file_name = '' ) {
374374
return content_url( '/boost-cache/static/' . $file_name );
375375
}
376376

377+
function jetpack_boost_get_minify_file_path( $file_name = '' ) {
378+
return WP_CONTENT_DIR . '/boost-cache/static/' . $file_name;
379+
}
380+
377381
/**
378382
* Detects requests within the `/_jb_static/` directory, and serves minified content.
379383
*

0 commit comments

Comments
 (0)