Making WordPress.org

Changeset 9284


Ignore:
Timestamp:
11/20/2019 06:59:20 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Cron Jobs: Clear the Memcache cache within WordPress after processing lots of posts to allow Jetpack Sync to have some memory free.

This avoids plenty of post-shutdown fatals in cron tasks WordPress.org is currently experiencing and consolidates such code to a single instance.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php

    r8975 r9284  
    310310    }
    311311
     312    /**
     313     * Clear caches for memory management.
     314     *
     315     * @static
     316     * @global \wpdb            $wpdb
     317     * @global \WP_Object_Cache $wp_object_cache
     318     */
     319    public static function clear_memory_heavy_variables() {
     320        global $wpdb, $wp_object_cache;
     321
     322        $wpdb->queries = [];
     323
     324        if ( is_object( $wp_object_cache ) ) {
     325            $wp_object_cache->cache          = [];
     326            $wp_object_cache->group_ops      = [];
     327            $wp_object_cache->memcache_debug = [];
     328        }
     329    }
    312330
    313331}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-meta-sync.php

    r9140 r9284  
    2626        $this->sync_ratings();
    2727        $this->update_tested_up_to();
     28
     29        Manager::clear_memory_heavy_variables();
    2830    }
    2931
     
    167169        $tested_values             = $wpdb->get_results( "SELECT post_id, post_name, meta_value FROM {$wpdb->postmeta} pm JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE meta_key = 'tested' AND meta_value IN( {$tested_meta_value_esc_sql} )" );
    168170
    169         foreach ( $tested_values as $row ) {
     171        foreach ( $tested_values as $i => $row ) {
    170172            update_post_meta(
    171173                $row->post_id,
     
    176178            // Update the API endpoints with the new data
    177179            API_Update_Updater::update_single_plugin( $row->post_name );
     180
     181            if ( $i % 100 === 0 ) {
     182                Manager::clear_memory_heavy_variables();
     183            }
    178184        }
    179185    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-support-resolved.php

    r6571 r9284  
    7070            }
    7171
    72             self::stop_the_insanity();
     72            Manager::clear_memory_heavy_variables();
    7373        }
    7474    }
    7575
    76     /**
    77      * Clear caches for memory management.
    78      *
    79      * @static
    80      * @global \wpdb            $wpdb
    81      * @global \WP_Object_Cache $wp_object_cache
    82      */
    83     protected static function stop_the_insanity() {
    84         global $wpdb, $wp_object_cache;
    85 
    86         $wpdb->queries = [];
    87 
    88         if ( is_object( $wp_object_cache ) ) {
    89             $wp_object_cache->cache          = [];
    90             $wp_object_cache->group_ops      = [];
    91             $wp_object_cache->memcache_debug = [];
    92             $wp_object_cache->stats          = [];
    93         }
    94     }
    9576}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-translation-sync.php

    r8461 r9284  
    3030
    3131            // Make sure the cache doesn't exhaust memory
    32             global $wp_object_cache;
    33             if ( is_object( $wp_object_cache ) ) {
    34                 $wp_object_cache->cache = array();
    35                 $wp_object_cache->stats = array( 'add' => 0, 'get' => 0, 'get_multi' => 0, 'delete' => 0);
    36                 $wp_object_cache->group_ops = array();
    37             }
     32            Manager::clear_memory_heavy_variables();
    3833
    3934            $args['offset'] += $args['posts_per_page'];
Note: See TracChangeset for help on using the changeset viewer.