Skip to content

Commit

Permalink
*Version bump to 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Mar 26, 2017
1 parent 1ff8951 commit 0d2c7f0
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 119 deletions.
9 changes: 9 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ This is used as a special version of the web page that forcibly disables support

== Changelog ==

### 0.5.0 ###

* Bug: Replace purge lock with disable_external_integration method due to the order that the actions run
* Bug: Disable external integration when purging cache from web check queue
* Enhancement: Improve redirect_canonical logic
* Enhancement: Rebuild cache system without using SQL
* Cleanup: Clean up code and fix typo with cache


### 0.4.5 ###

* Change: Generalize fix_woocommerce_rewrite to fix_rewrites
Expand Down
236 changes: 118 additions & 118 deletions lib/class-wp-criticalcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class WP_CriticalCSS {
/**
*
*/
const VERSION = '0.4.5';
const VERSION = '0.5.0';

/**
*
Expand Down Expand Up @@ -238,13 +238,6 @@ public static function update_settings( array $settings ) {
}
}

/**
*
*/
public static function reset_web_check_transients() {
self::delete_cache_branch();
}

/**
*
*/
Expand Down Expand Up @@ -607,6 +600,87 @@ public static function get_item_hash( $item ) {
return md5( serialize( $type ) );
}

protected function get_cache_fragment( $path ) {
if ( ! in_array( 'cache', $path ) ) {
array_unshift( $path, 'cache' );
}

return get_transient( self::TRANSIENT_PREFIX . implode( '_', $path ) );
}

protected static function update_cache_fragment( $path, $value ) {
if ( ! in_array( 'cache', $path ) ) {
array_unshift( $path, 'cache' );
}
self::build_cache_tree( array_slice( $path, 0, count( $path ) - 1 ) );
self::update_tree_branch( $path, $value );
}

protected static function build_cache_tree( $path ) {
$levels = count( $path );
$expire = get_rocket_purge_cron_interval();
for ( $i = 0; $i < $levels; $i ++ ) {
$transient_id = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 1 ) );
$transient_cache_id = $transient_id;
if ( 'cache' != $path[ $i ] ) {
$transient_cache_id .= '_cache';
}
$transient_cache_id .= '_1';
$cache = get_transient( $transient_cache_id );
$transient_value = array();
if ( $i + 1 < $levels ) {
$transient_value[] = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 2 ) );
}
if ( ! is_null( $cache ) && false !== $cache ) {
$transient_value = array_unique( array_merge( $cache, $transient_value ) );
}
set_transient( $transient_cache_id, $transient_value, $expire );
$transient_counter_id = $transient_id;
if ( 'cache' != $path[ $i ] ) {
$transient_counter_id .= '_cache';
}
$transient_counter_id .= '_count';
$transient_counter = get_transient( $transient_counter_id );
if ( is_null( $transient_counter ) || false === $transient_counter ) {
set_transient( $transient_counter_id, 1, $expire );
}
}
}

protected static function update_tree_branch( $path, $value ) {
$branch = self::TRANSIENT_PREFIX . implode( '_', $path );
$parent_path = array_slice( $path, 0, count( $path ) - 1 );
$parent = self::TRANSIENT_PREFIX . implode( '_', $parent_path );
$counter_transient = $parent;
$cache_transient = $parent;
if ( 'cache' != end( $parent_path ) ) {
$counter_transient .= '_cache';
$cache_transient .= '_cache';
}
$counter_transient .= '_count';
$counter = (int) get_transient( $counter_transient );
$cache_transient .= "_{$counter}";
$cache = get_transient( $cache_transient );
$count = count( $cache );
$cache_keys = array_flip( $cache );
$expire = get_rocket_purge_cron_interval();
if ( ! isset( $cache_keys[ $branch ] ) ) {
if ( $count >= apply_filters( 'rocket_async_css_max_branch_length', 50 ) ) {
$counter ++;
set_transient( $counter_transient, $counter, $expire );
$cache_transient = $parent;
if ( 'cache' != end( $parent_path ) ) {
$cache_transient .= '_cache';
}
$cache_transient .= "_{$counter}";
$cache = array();
}
$cache[] = $branch;
set_transient( $cache_transient, $cache, $expire );
}
set_transient( $branch, $value, $expire );
}

/**
* @return int
*/
Expand Down Expand Up @@ -816,6 +890,42 @@ public static function sync_options( $value, $old_value ) {
return $value;
}

/**
*
*/
public static function reset_web_check_transients() {
self::delete_cache_branch();
}

protected static function delete_cache_branch( $path = array() ) {
if ( is_array( $path ) ) {
if ( ! empty( $path ) ) {
$path = self::TRANSIENT_PREFIX . implode( '_', $path ) . '_';
} else {
$path = self::TRANSIENT_PREFIX;
}
}
$counter_transient = "{$path}cache_count";
$counter = get_transient( $counter_transient );

if ( is_null( $counter ) || false === $counter ) {
delete_transient( rtrim( $path, '_' ) );

return;
}
for ( $i = 1; $i <= $counter; $i ++ ) {
$transient_name = "{$path}cache_{$i}";
$cache = get_transient( "{$path}cache_{$i}" );
if ( ! empty( $cache ) ) {
foreach ( $cache as $sub_branch ) {
self::delete_cache_branch( "{$sub_branch}_" );
}
delete_transient( $transient_name );
}
}
delete_transient( $counter_transient );
}

public static function reset_web_check_post_transient( $post ) {
$post = get_post( $post );
$hash = self::get_item_hash( array( 'object_id' => $post->ID, 'type' => 'post' ) );
Expand Down Expand Up @@ -886,114 +996,4 @@ public static function admin_menu( WP_Admin_Bar $wp_admin_bar ) {
), admin_url( 'admin-post.php' ) ), $action ),
) );
}

protected function get_cache_fragment( $path ) {
if ( ! in_array( 'cache', $path ) ) {
array_unshift( $path, 'cache' );
}

return get_transient( self::TRANSIENT_PREFIX . implode( '_', $path ) );
}

protected static function update_cache_fragment( $path, $value ) {
if ( ! in_array( 'cache', $path ) ) {
array_unshift( $path, 'cache' );
}
self::build_cache_tree( array_slice( $path, 0, count( $path ) - 1 ) );
self::update_tree_branch( $path, $value );
}

protected static function build_cache_tree( $path ) {
$levels = count( $path );
$expire = get_rocket_purge_cron_interval();
for ( $i = 0; $i < $levels; $i ++ ) {
$transient_id = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 1 ) );
$transient_cache_id = $transient_id;
if ( 'cache' != $path[ $i ] ) {
$transient_cache_id .= '_cache';
}
$transient_cache_id .= '_1';
$cache = get_transient( $transient_cache_id );
$transient_value = array();
if ( $i + 1 < $levels ) {
$transient_value[] = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 2 ) );
}
if ( ! is_null( $cache ) && false !== $cache ) {
$transient_value = array_unique( array_merge( $cache, $transient_value ) );
}
set_transient( $transient_cache_id, $transient_value, $expire );
$transient_counter_id = $transient_id;
if ( 'cache' != $path[ $i ] ) {
$transient_counter_id .= '_cache';
}
$transient_counter_id .= '_count';
$transient_counter = get_transient( $transient_counter_id );
if ( is_null( $transient_counter ) || false === $transient_counter ) {
set_transient( $transient_counter_id, 1, $expire );
}
}
}

protected static function update_tree_branch( $path, $value ) {
$branch = self::TRANSIENT_PREFIX . implode( '_', $path );
$parent_path = array_slice( $path, 0, count( $path ) - 1 );
$parent = self::TRANSIENT_PREFIX . implode( '_', $parent_path );
$counter_transient = $parent;
$cache_transient = $parent;
if ( 'cache' != end( $parent_path ) ) {
$counter_transient .= '_cache';
$cache_transient .= '_cache';
}
$counter_transient .= '_count';
$counter = (int) get_transient( $counter_transient );
$cache_transient .= "_{$counter}";
$cache = get_transient( $cache_transient );
$count = count( $cache );
$cache_keys = array_flip( $cache );
$expire = get_rocket_purge_cron_interval();
if ( ! isset( $cache_keys[ $branch ] ) ) {
if ( $count >= apply_filters( 'rocket_async_css_max_branch_length', 50 ) ) {
$counter ++;
set_transient( $counter_transient, $counter, $expire );
$cache_transient = $parent;
if ( 'cache' != end( $parent_path ) ) {
$cache_transient .= '_cache';
}
$cache_transient .= "_{$counter}";
$cache = array();
}
$cache[] = $branch;
set_transient( $cache_transient, $cache, $expire );
}
set_transient( $branch, $value, $expire );
}

protected static function delete_cache_branch( $path = array() ) {
if ( is_array( $path ) ) {
if ( ! empty( $path ) ) {
$path = self::TRANSIENT_PREFIX . implode( '_', $path ) . '_';
} else {
$path = self::TRANSIENT_PREFIX;
}
}
$counter_transient = "{$path}cache_count";
$counter = get_transient( $counter_transient );

if ( is_null( $counter ) || false === $counter ) {
delete_transient( rtrim( $path, '_' ) );

return;
}
for ( $i = 1; $i <= $counter; $i ++ ) {
$transient_name = "{$path}cache_{$i}";
$cache = get_transient( "{$path}cache_{$i}" );
if ( ! empty( $cache ) ) {
foreach ( $cache as $sub_branch ) {
self::delete_cache_branch( "{$sub_branch}_" );
}
delete_transient( $transient_name );
}
}
delete_transient( $counter_transient );
}
}
2 changes: 1 addition & 1 deletion wp-criticalcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: WP Critical CSS
Plugin URI: https://github.com/pcfreak30/wp-criticalcss
Description: Use CriticalCSS.com web service to automatically create the required CSS for above the fold
Version: 0.4.5
Version: 0.5.0
Author: Derrick Hammer
Author URI: https://www.derrickhammer.com
License: GPL3
Expand Down

0 comments on commit 0d2c7f0

Please sign in to comment.