Making WordPress.org

Changeset 2836


Ignore:
Timestamp:
03/28/2016 09:01:37 PM (9 years ago)
Author:
obenland
Message:

Plugin Directory: Cache commit access data to avoid multible db calls.

Reduces DB calls on edit.php from 127 to 11.

See #1570, #1571.

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

Legend:

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

    r2829 r2836  
    4343    public function init() {
    4444        load_plugin_textdomain( 'wporg-plugins' );
     45
     46        wp_cache_add_global_groups( 'wporg-plugins' );
    4547
    4648        register_post_type( 'plugin', array(
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r2777 r2836  
    3838        global $wpdb;
    3939
    40         return $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) );
     40        if ( false === ( $committers = wp_cache_get( "{$plugin_slug}_committer", 'wporg-plugins' ) ) ) {
     41            $committers = $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) );
     42
     43            wp_cache_set( "{$plugin_slug}_committer", $committers, 'wporg-plugins' );
     44        }
     45
     46        return $committers;
    4147    }
    4248
     49    /**
     50     * Retrieve a list of plugins a specific user has commit to.
     51     *
     52     * @param int|\WP_User $user The user.
     53     * @return array The list of plugins the user has commit to.
     54     */
    4355    public static function get_users_write_access_plugins( $user ) {
    4456        global $wpdb;
     
    5062        }
    5163
    52         $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) );
    53         $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins );
     64        if ( false === ( $plugins = wp_cache_get( "{$user->user_login}_committer", 'wporg-plugins' ) ) ) {
     65            $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) );
     66            $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins );
     67
     68            wp_cache_set( "{$user->user_login}_committer", $plugins, 'wporg-plugins' );
     69        }
    5470
    5571        return $plugins;
     
    7793        $existing_committers = self::get_plugin_committers( $plugin_slug );
    7894        if ( in_array( $user->user_login, $existing_committers, true ) ) {
    79             // User already has write access
     95            // User already has write access.
    8096            return true;
    8197        }
     98
     99        wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
     100        wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
    82101
    83102        return (bool) $wpdb->insert(
     
    86105                'path'   => "/{$plugin_slug}",
    87106                'user'   => $user->user_login,
    88                 'access' => 'rw'
     107                'access' => 'rw',
    89108            )
    90109        );
     
    109128        }
    110129
     130        wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
     131        wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
     132
    111133        return $wpdb->delete(
    112134            PLUGINS_TABLE_PREFIX . 'svn_access',
Note: See TracChangeset for help on using the changeset viewer.