Skip to content

Commit

Permalink
*Prevent duplicate web request queue items by querying the serialized…
Browse files Browse the repository at this point in the history
… data from the options table
  • Loading branch information
pcfreak30 committed Jan 25, 2017
1 parent 923233e commit 5fc7783
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/class-wp-criticalcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ public static function purge_page_cache( $type, $object_id, $url ) {
*
*/
public static function print_styles() {
global $wpdb;
if ( ! get_query_var( 'nocache' ) && ! is_404() ) {
$cache = self::get_cache();
$style_handle = null;
Expand All @@ -430,8 +431,11 @@ public static function print_styles() {
$id = md5( serialize( $type ) );
$check = get_transient( "criticalcss_web_check_$id" );
if ( empty( $check ) ) {
self::$_web_check_queue->push_to_queue( $type )->save();
set_transient( "criticalcss_web_check_$id", true, self::get_expire_period() );
$wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->options} WHERE option_value = %s", serialize( $type ) ) );
if ( empty( $wpdb->num_rows ) ) {
self::$_web_check_queue->push_to_queue( $type )->save();
set_transient( "criticalcss_web_check_$id", true, self::get_expire_period() );
}
}

}
Expand All @@ -453,12 +457,12 @@ public static function get_cache( $item = array() ) {
* @return mixed|null
*/
public static function get_item_data( $item = array(), $name ) {
$value = null;
$value = null;
if ( empty( $item ) ) {
$item = self::get_current_page_type();
}
if ( 'url' == $item['type'] ) {
$name = "criticalcss_url_{$name}_" . md5( $item['url'] );
$name = "criticalcss_url_{$name}_" . md5( $item['url'] );
$value = get_transient( $name );
} else {
$name = "criticalcss_{$name}";
Expand Down

0 comments on commit 5fc7783

Please sign in to comment.