Making WordPress.org


Ignore:
Timestamp:
04/21/2016 05:57:55 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Add a shim to allow us to retrieve the downloads count from postmeta (although the count is stored elsewhere for now).

See #1596

File:
1 edited

Legend:

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

    r2986 r2991  
    2020
    2121    /**
     22     * @param \WP_Post|int $post Optional.
     23     * @return int
     24     */
     25    static function get_downloads_count( $post = null ) {
     26        $post = get_post( $post );
     27
     28        if ( false === ( $count = wp_cache_get( $post->ID, 'plugin_download_count' ) ) ) {
     29            global $wpdb;
     30
     31            // TODO: While the plugin ZIPs are still being served by bbPress, the download stats are stored there.
     32            $count = $wpdb->get_var( $wpdb->prepare( "SELECT downloads FROM `" . PLUGINS_TABLE_PREFIX . "download_counts` WHERE topic_id = (SELECT topic_id FROM `" . PLUGINS_TABLE_PREFIX . "topics` WHERE topic_slug = %s )", $post->post_name ) );
     33
     34            wp_cache_set( $post->ID, $count, 'plugin_download_count', HOUR_IN_SECONDS );
     35        }
     36
     37        return (int) $count;
     38    }
     39
     40    /**
    2241     * @return int
    2342     */
     
    2645            global $wpdb;
    2746
    28             $count = $wpdb->get_var( "SELECT SUM(downloads) FROM `plugin_2_stats`" );
    29             wp_cache_add( 'plugin_download_count', $count, 'plugin_download_count', DAY_IN_SECONDS );
     47            $count = $wpdb->get_var( "SELECT SUM(downloads) FROM `" . PLUGINS_TABLE_PREFIX . "stats`" );
     48            wp_cache_set( 'plugin_download_count', $count, 'plugin_download_count', DAY_IN_SECONDS );
    3049        }
    3150
Note: See TracChangeset for help on using the changeset viewer.