1
0
mirror of https://github.com/gamaio/lobli.git synced 2024-12-22 11:42:40 +00:00

Change click tracking to sorted set.

Using a sorted set makes it easier to sort from highest to lowest on the stats page.
Minor change how tracking is done on the index and link checking has been updated.
This commit is contained in:
alopexc0de 2014-08-10 18:29:17 -04:00
parent 485f1fa66f
commit 4ad0f8ce74
No known key found for this signature in database
GPG Key ID: 48E847F18074C953
3 changed files with 15 additions and 15 deletions

View File

@ -47,8 +47,7 @@
$redis->rpush("links:$short", date("d/m/Y", strtotime($str)));
$redis->expireAt("links:$short", $now+$xTime);
$redis->set("tracking:clicks:$link", 1);
$redis->expireAt("tracking:clicks:$link", $now+$xTime);
$redis->zAdd("tracking:clicks", 1, $link);
return "0$seperator$short$seperator$title";
}

View File

@ -38,21 +38,19 @@
if(!in_array($_SERVER['REMOTE_ADDR'], $ipTrack)){ // Check to see if visiter hit this link before (This would make it a lot easier to skew statistics if anyone would register multiples times)
$redis->rPush("tracking:ip:$link", $_SERVER['REMOTE_ADDR']);
// Tracking code
$tracking = $redis->get("tracking:clicks:$link");
$trTtl = $redis->ttl("links:id:$link");
$trTtl = $redis->ttl("links:$link");
if(!$tracking || $trTtl != -2){
$tracking = $redis->set("tracking:clicks:$link", 1);
if($trTtl != -2){
$tracking = $redis->zIncrBy("tracking:clicks", 1, $link);
}else{
if($trTtl == -2){ // The link has been deleted, no need to track it anymore
$redis->zRem("tracking:clicks", $link);
break;
}
$tracking = $redis->incr("tracking:clicks:$link");
}
}
$short = $redis->get("links:id:$link");
$short = $redis->get("links:$link");
if($short){
echo $short;
exit(5);

View File

@ -45,20 +45,23 @@
require('Include/PHP/db.php');
$stats = $redis->keys("tracking:clicks:*");
rsort($stats);
$stats = $redis->zRangeByScore("tracking:clicks", "-inf", "+inf");
$stats = array_reverse($stats);
$stats = array_slice($stats, 0, 5, true);
foreach($stats as $stat){ // There should only be 5, but the page doesn't limit how many
$id = explode(":", $stat);
$id = $id[2]; // Grab just the short link ID
foreach($stats as $id){ // There should only be 5, but the page doesn't limit how many
$trTtl = $redis->ttl("links:$id");
if($trTtl == -2){ // The link has been deleted, no need to track it anymore
$redis->zRem("tracking:clicks", $id;
continue;
}
$linkData = $redis->lRange("links:$id", 0, -1);
$link = $linkData[0];
$title = $linkData[1];
$date = $linkData[2];
$trackClicks = $redis->get("tracking:clicks:$id");
$trackClicks = $redis->zScore("tracking:clicks", $id);
echo "
<tr class=\"success\">