WordPress.org

Making WordPress.org

Changeset 5181


Ignore:
Timestamp:
03/28/2017 09:58:11 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Use better cache groups in the SVN access functions & ensure that when syncing the Committer taxonomy, that the data isn't stale from the cache.

File:
1 edited

Legend:

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

    r4388 r5181  
    5050            $number = 2;
    5151        }
    52         if ( false === ( $reviews = wp_cache_get( "{$plugin_slug}_last{$number}_reviews", 'wporg-plugins' ) ) ) {
     52        if ( false === ( $reviews = wp_cache_get( "{$plugin_slug}_last{$number}", 'plugin-reviews' ) ) ) {
    5353            global $wpdb;
    5454
     
    6363            LIMIT %d", $plugin_slug, $number ) );
    6464
    65             wp_cache_set( "{$plugin_slug}_last{$number}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS );
     65            wp_cache_set( "{$plugin_slug}_last{$number}", $reviews, 'plugin-reviews', 12 * HOUR_IN_SECONDS );
    6666        }
    6767
     
    7676     *
    7777     * @param string $plugin_slug The plugin slug.
     78     * @param bool   $use_cache   If we should use the cache, or fetch new data.
    7879     * @return array The list of user_login's which have commit.
    7980     */
    80     public static function get_plugin_committers( $plugin_slug ) {
    81         if ( false === ( $committers = wp_cache_get( "{$plugin_slug}_committer", 'wporg-plugins' ) ) ) {
     81    public static function get_plugin_committers( $plugin_slug, $use_cache = true ) {
     82        if ( ! $plugin_slug ) {
     83            return array();
     84        }
     85
     86        if ( ! $use_cache || false === ( $committers = wp_cache_get( $plugin_slug, 'plugin-committers' ) ) ) {
    8287            global $wpdb;
    8388
    8489            $committers = $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) );
    8590
    86             wp_cache_set( "{$plugin_slug}_committer", $committers, 'wporg-plugins' );
     91            wp_cache_set( $plugin_slug, $committers, 'plugin-committers', 12 * HOUR_IN_SECONDS );
    8792        }
    8893
     
    108113        }
    109114
    110         if ( false === ( $plugins = wp_cache_get( "{$user->user_login}_committer", 'wporg-plugins' ) ) ) {
     115        if ( false === ( $plugins = wp_cache_get( $user->user_login, 'committer-plugins' ) ) ) {
    111116            global $wpdb;
    112117
     
    116121            }, $plugins );
    117122
    118             wp_cache_set( "{$user->user_login}_committer", $plugins, 'wporg-plugins' );
     123            wp_cache_set( $user->user_login, $plugins, 'committer-plugins', 12 * HOUR_IN_SECONDS );
    119124        }
    120125
     
    135140
    136141        $committer_slugs = array();
    137         foreach ( Tools::get_plugin_committers( $plugin_slug ) as $committer ) {
     142        foreach ( Tools::get_plugin_committers( $plugin_slug, false /* Do not use the cache */ ) as $committer ) {
    138143            $user = get_user_by( 'login', $committer );
    139144            if ( $user ) {
     
    162167        }
    163168
    164         if ( ! $user->exists() || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
     169        if ( ! $user->exists() || ! $plugin_slug || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
    165170            return false;
    166171        }
     
    179184        ) );
    180185
    181         wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
    182         wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
     186        wp_cache_delete( $plugin_slug, 'plugin-committers' );
     187        wp_cache_delete( $user->user_login, 'committer-plugins' );
    183188        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
    184189
     
    203208        }
    204209
    205         if ( ! $user->exists() || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
     210        if ( ! $user->exists() || ! $plugin_slug || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
    206211            return false;
    207212        }
     
    212217        ) );
    213218
    214         wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
    215         wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
     219        wp_cache_delete( $plugin_slug, 'plugin-committers' );
     220        wp_cache_delete( $user->user_login, 'committer-plugins' );
    216221        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
    217222
Note: See TracChangeset for help on using the changeset viewer.