Permalink
Browse files

Add transient cache to in referring data

  • Loading branch information...
mostafasoufi committed Nov 27, 2017
1 parent 5a362f4 commit db55c13ebecd9764cfb908210fa60ba05ae5f80a
Showing with 13 additions and 10 deletions.
  1. +13 −10 includes/log/widgets/referring.php
@@ -1,8 +1,12 @@
<?php
function wp_statistics_generate_referring_postbox_content( $count = 10 ) {
global $wpdb, $WP_Statistics;
$result = $wpdb->get_results(
"SELECT `ref`, COUNT(`ref`) AS `count` FROM(
// Check for transient. If none, then get from database.
if ( false === ( $result = get_transient( 'wps_top_referring' ) ) ) {
// Get data from database.
$result = $wpdb->get_results(
"SELECT `ref`, COUNT(`ref`) AS `count` FROM(
SELECT SUBSTRING_INDEX(
REPLACE(REPLACE(REPLACE(`referred`, 'http://', ''), 'https://', ''), 'www.', ''),
'/', 1
@@ -13,7 +17,12 @@ function wp_statistics_generate_referring_postbox_content( $count = 10 ) {
GROUP BY `ref`
ORDER BY `count` DESC
LIMIT {$count}"
);
);
// Put the results in a transient. Expire after 24 hours.
set_transient( 'wps_top_referring', $result, 24 * HOUR_IN_SECONDS );
}
?>
<table width="100%" class="widefat table-stats left-align" id="last-referrer">
<tr>
@@ -23,13 +32,7 @@ function wp_statistics_generate_referring_postbox_content( $count = 10 ) {
<?php
foreach ( $result as $item ) {
echo "<tr>";
echo "<td><a href='?page=" .
WP_Statistics::$page['referrers'] .
"&referr=" .
$item->ref .
"'>" .
number_format_i18n($item->count) .
"</a></td>";
echo "<td><a href='?page=" .WP_Statistics::$page['referrers'] . "&referr=" . $item->ref . "'>" . number_format_i18n($item->count) . "</a></td>";
echo "<td>" . $WP_Statistics->get_referrer_link($item->ref) . "</td>";
echo "</tr>";
}

0 comments on commit db55c13

Please sign in to comment.