Making WordPress.org

Changeset 4728


Ignore:
Timestamp:
01/19/2017 06:48:03 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Add stat recording for downloads to bump the plugin download counts.

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/jobs/class-meta-sync.php

    r4423 r4728  
    3434
    3535        $download_count_table = PLUGINS_TABLE_PREFIX . 'download_counts';
    36         $bbpress_topic_slug_table = PLUGINS_TABLE_PREFIX . 'topics';
    3736
    3837        $changed_download_counts = $wpdb->get_results(
    3938            "SELECT p.id as post_id, downloads
    4039            FROM `{$wpdb->posts}` p
    41                 JOIN `{$bbpress_topic_slug_table}` t ON p.post_name = t.topic_slug
    42                 JOIN `{$download_count_table}` c on t.topic_id = c.topic_id
     40                JOIN `{$download_count_table}` c on p.post_name = c.plugin_slug
    4341                LEFT JOIN `{$wpdb->postmeta}` pm ON p.id = pm.post_id AND pm.meta_key = 'downloads'
    4442
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-serve.php

    r3081 r4728  
    179179        global $wpdb;
    180180
    181         $stats = array(
     181        $stats_dedup_log_table = PLUGINS_TABLE_PREFIX . 'downloads';
     182        $stats_download_table = PLUGINS_TABLE_PREFIX . 'download_counts';
     183        $stats_download_daily_table = PLUGINS_TABLE_PREFIX . 'stats';
     184
     185        // Very basic de-duplication for downloads.
     186        $recent = $wpdb->get_var( $wpdb->prepare(
     187            "SELECT `client_ip`
     188            FROM {$stats_dedup_log_table}
     189            WHERE
     190                plugin_slug = %s AND
     191                client_ip = %s AND
     192                user_agent = %s AND
     193                stamp BETWEEN %s AND %s
     194            LIMIT 1",
     195            $request['slug'],
     196            $_SERVER['REMOTE_ADDR'],
     197            $_SERVER['HTTP_USER_AGENT'],
     198            gmdate( 'Y-m-d 00:00:00' ),
     199            gmdate( 'Y-m-d 23:59:59' )
     200        ) );
     201
     202        if ( $recent ) {
     203            return;
     204        }
     205
     206        $wpdb->query( $wpdb->prepare(
     207            "INSERT INTO {$stats_download_table} (`plugin_slug`, `downloads`) VALUES ( %s, 1 ) ON DUPLICATE KEY UPDATE `downloads` = `downloads` + 1",
     208            $stats['plugin_slug']
     209        ) );
     210
     211        $wpdb->query( $wpdb->prepare(
     212            "INSERT INTO {$stats_download_daily_table} (`plugin_slug`, `stamp`, `downloads`) VALUES ( %s, %s, 1 ) ON DUPLICATE KEY UPDATE `downloads` = `downloads` + 1",
     213            $stats['plugin_slug'],
     214            gmdate( 'Y-m-d' )
     215        ) );
     216
     217        $wpdb->insert( $stats_dedup_log_table, array(
    182218            'plugin_slug' => $request['slug'],
    183219            'client_ip'   => $_SERVER['REMOTE_ADDR'],
    184             'client_host' => gethostbyaddr( $_SERVER['REMOTE_ADDR'] ),
    185             'user_agent'  => $_SERVER['HTTP_USER_AGENT']
    186         );
    187         // $wpdb->insert( stats_table, $stats );
    188         // TODO: This is stored in bbPress tables still.
    189         // $post_id = $this->get_post_id( $request['slug'] );
    190         // $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = meta_value + 1 WHERE post_id = %d AND meta_key = 'downloads'", $post_id ) );
     220            'user_agent'  => $_SERVER['HTTP_USER_AGENT'],
     221            'stamp'       => gmdate( 'Y-m-d H:i:s' )
     222        ) );
     223
    191224    }
    192225
Note: See TracChangeset for help on using the changeset viewer.