Empty commit

This commit is contained in:
Git 2013-03-18 08:00:24 +00:00
parent 0a0d9b8aa6
commit 6a47225ddd
2 changed files with 97 additions and 56 deletions

View File

@ -22,6 +22,7 @@
g.ID,
g.Name,
g.CategoryID,
g.wikiImage,
g.TagList,
t.Format,
t.Encoding,
@ -36,7 +37,8 @@
t.Snatched,
t.Seeders,
t.Leechers,
((t.Size * t.Snatched) + (t.Size * 0.5 * t.Leechers)) AS Data
((t.Size * t.Snatched) + (t.Size * 0.5 * t.Leechers)) AS Data,
g.ReleaseType
FROM torrents AS t
LEFT JOIN torrents_group AS g ON g.ID = t.GroupID ";
@ -44,87 +46,117 @@
if($Details == 'all' || $Details == 'day') {
if (!$TopTorrentsActiveLastDay = $Cache->get_value('top10tor_day_'.$Limit.$WhereSum)) {
$DayAgo = time_minus(86400);
$Query = $BaseQuery.' WHERE t.Seeders>0 AND ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'$DayAgo'
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastDay = $DB->to_array();
$Cache->cache_value('top10tor_day_'.$Limit.$WhereSum,$TopTorrentsActiveLastDay,3600*2);
if ($Cache->get_query_lock('top10')) {
$DayAgo = time_minus(86400);
$Query = $BaseQuery.' WHERE t.Seeders>0 AND ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'$DayAgo'
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastDay = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_day_'.$Limit.$WhereSum,$TopTorrentsActiveLastDay,3600*2);
$Cache->clear_query_lock('top10');
} else {
$TopTorrentsActiveLastDay = false;
}
}
$OuterResults[] = generate_torrent_json('Most Active Torrents Uploaded in the Past Day', 'day', $TopTorrentsActiveLastDay, $Limit);
}
if($Details == 'all' || $Details == 'week') {
if (!$TopTorrentsActiveLastWeek = $Cache->get_value('top10tor_week_'.$Limit.$WhereSum)) {
$WeekAgo = time_minus(604800);
$Query = $BaseQuery.' WHERE ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'$WeekAgo'
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastWeek = $DB->to_array();
$Cache->cache_value('top10tor_week_'.$Limit.$WhereSum,$TopTorrentsActiveLastWeek,3600*6);
if ($Cache->get_query_lock('top10')) {
$WeekAgo = time_minus(604800);
$Query = $BaseQuery.' WHERE ';
if (!empty($Where)) { $Query .= $Where.' AND '; }
$Query .= "
t.Time>'$WeekAgo'
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveLastWeek = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_week_'.$Limit.$WhereSum,$TopTorrentsActiveLastWeek,3600*6);
$Cache->clear_query_lock('top10');
} else {
$TopTorrentsActiveLastWeek = false;
}
}
$OuterResults[] = generate_torrent_json('Most Active Torrents Uploaded in the Past Week', 'week', $TopTorrentsActiveLastWeek, $Limit);
}
if($Details == 'all' || $Details == 'overall') {
if (!$TopTorrentsActiveAllTime = $Cache->get_value('top10tor_overall_'.$Limit.$WhereSum)) {
// IMPORTANT NOTE - we use WHERE t.Seeders>500 in order to speed up this query. You should remove it!
$Query = $BaseQuery;
if (!empty($Where)) { $Query .= ' WHERE '.$Where; }
elseif ($Details=='all') { $Query .= " WHERE t.Seeders>500 "; }
$Query .= "
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveAllTime = $DB->to_array();
$Cache->cache_value('top10tor_overall_'.$Limit.$WhereSum,$TopTorrentsActiveAllTime,3600*6);
if ($Cache->get_query_lock('top10')) {
// IMPORTANT NOTE - we use WHERE t.Seeders>500 in order to speed up this query. You should remove it!
$Query = $BaseQuery;
if (!empty($Where)) { $Query .= ' WHERE '.$Where; }
elseif ($Details=='all') { $Query .= " WHERE t.Seeders>500 "; }
$Query .= "
ORDER BY (t.Seeders + t.Leechers) DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsActiveAllTime = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_overall_'.$Limit.$WhereSum,$TopTorrentsActiveAllTime,3600*6);
$Cache->clear_query_lock('top10');
} else {
$TopTorrentsActiveAllTime = false;
}
}
$OuterResults[] = generate_torrent_json('Most Active Torrents of All Time', 'overall', $TopTorrentsActiveAllTime, $Limit);
}
if(($Details == 'all' || $Details == 'snatched') && empty($Where)) {
if (!$TopTorrentsSnatched = $Cache->get_value('top10tor_snatched_'.$Limit.$WhereSum)) {
$Query = $BaseQuery;
$Query .= "
ORDER BY t.Snatched DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSnatched = $DB->to_array();
$Cache->cache_value('top10tor_snatched_'.$Limit.$WhereSum,$TopTorrentsSnatched,3600*6);
if ($Cache->get_query_lock('top10')) {
$Query = $BaseQuery;
$Query .= "
ORDER BY t.Snatched DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSnatched = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_snatched_'.$Limit.$WhereSum,$TopTorrentsSnatched,3600*6);
$Cache->clear_query_lock('top10');
} else {
$TopTorrentsSnatched = false;
}
}
$OuterResults[] = generate_torrent_json('Most Snatched Torrents', 'snatched', $TopTorrentsSnatched, $Limit);
}
if(($Details == 'all' || $Details == 'data') && empty($Where)) {
if (!$TopTorrentsTransferred = $Cache->get_value('top10tor_data_'.$Limit.$WhereSum)) {
// IMPORTANT NOTE - we use WHERE t.Snatched>100 in order to speed up this query. You should remove it!
$Query = $BaseQuery;
if ($Details=='all') { $Query .= " WHERE t.Snatched>100 "; }
$Query .= "
ORDER BY Data DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsTransferred = $DB->to_array();
$Cache->cache_value('top10tor_data_'.$Limit.$WhereSum,$TopTorrentsTransferred,3600*6);
if ($Cache->get_query_lock('top10')) {
// IMPORTANT NOTE - we use WHERE t.Snatched>100 in order to speed up this query. You should remove it!
$Query = $BaseQuery;
if ($Details=='all') { $Query .= " WHERE t.Snatched>100 "; }
$Query .= "
ORDER BY Data DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsTransferred = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_data_'.$Limit.$WhereSum,$TopTorrentsTransferred,3600*6);
$Cache->clear_query_lock('top10');
} else {
$TopTorrentsTransferred = false;
}
}
$OuterResults[] = generate_torrent_json('Most Data Transferred Torrents', 'data', $TopTorrentsTransferred, $Limit);
}
if(($Details == 'all' || $Details == 'seeded') && empty($Where)) {
if (!$TopTorrentsSeeded = $Cache->get_value('top10tor_seeded_'.$Limit.$WhereSum)) {
$Query = $BaseQuery."
ORDER BY t.Seeders DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSeeded = $DB->to_array();
$Cache->cache_value('top10tor_seeded_'.$Limit.$WhereSum,$TopTorrentsSeeded,3600*6);
if ($Cache->get_query_lock('top10')) {
$Query = $BaseQuery."
ORDER BY t.Seeders DESC
LIMIT $Limit;";
$DB->query($Query);
$TopTorrentsSeeded = $DB->to_array(false, MYSQLI_NUM);
$Cache->cache_value('top10tor_seeded_'.$Limit.$WhereSum,$TopTorrentsSeeded,3600*6);
$Cache->clear_query_lock('top10');
} else {
$TopTorrentsSeeded = false;
}
}
$OuterResults[] = generate_torrent_json('Best Seeded Torrents', 'seeded', $TopTorrentsSeeded, $Limit);
}
@ -141,10 +173,19 @@
function generate_torrent_json($Caption, $Tag, $Details, $Limit) {
global $LoggedUser,$Categories;
$results = array();
if ($Details === false) {
// Failed to get cache lock; server is (hopefully) already processing a top10 request
return array(
'caption' => $Caption,
'tag' => $Tag,
'limit' => (int) $Limit,
'results' => array()
);
}
foreach ($Details as $Detail) {
list($TorrentID,$GroupID,$GroupName,$GroupCategoryID,$TorrentTags,
list($TorrentID,$GroupID,$GroupName,$GroupCategoryID,$WikiImage,$TorrentTags,
$Format,$Encoding,$Media,$Scene,$HasLog,$HasCue,$LogScore,$Year,$GroupYear,
$RemasterTitle,$Snatched,$Seeders,$Leechers,$Data) = $Detail;
$RemasterTitle,$Snatched,$Seeders,$Leechers,$Data,$ReleaseType) = $Detail;
$Artist = Artists::display_artists(Artists::get_artist($GroupID), false, true);
$TruncArtist = substr($Artist, 0, strlen($Artist)-3);

View File

@ -59,7 +59,7 @@
} else {
$RS .= " i.JoinDate > '".time_minus(3600*24*3)."'";
}
$RS .= " ORDER BY i.Joindate DESC";
$RS .= " ORDER BY i.Joindate DESC LIMIT $Limit";
$QueryID = $DB->query($RS);
$DB->query("SELECT FOUND_ROWS()");
list($Results) = $DB->next_record();