Esempio n. 1
0
$Query = '
	SELECT v.GroupID, v.Ups, v.Total, v.Score
	FROM torrents_votes AS v';
if (!empty($Where)) {
    $Query .= "\n\t\tJOIN torrents_group AS g ON g.ID = v.GroupID\n\tWHERE {$Where} AND ";
} else {
    $Query .= '
	WHERE ';
}
$Query .= "\n\t\tScore > 0\n\tORDER BY Score DESC\n\tLIMIT {$Limit}";
$TopVotes = $Cache->get_value('top10votes_' . $Limit . $WhereSum);
if ($TopVotes === false) {
    if ($Cache->get_query_lock('top10votes')) {
        $DB->query($Query);
        $Results = $DB->to_array('GroupID', MYSQLI_ASSOC, false);
        $Ranks = Votes::calc_ranks($DB->to_pair('GroupID', 'Score', false));
        $Groups = Torrents::get_groups(array_keys($Results));
        $TopVotes = array();
        foreach ($Results as $GroupID => $Votes) {
            $TopVotes[$GroupID] = $Groups[$GroupID];
            $TopVotes[$GroupID]['Ups'] = $Votes['Ups'];
            $TopVotes[$GroupID]['Total'] = $Votes['Total'];
            $TopVotes[$GroupID]['Score'] = $Votes['Score'];
            $TopVotes[$GroupID]['Rank'] = $Ranks[$GroupID];
        }
        $Cache->cache_value('top10votes_' . $Limit . $WhereSum, $TopVotes, 60 * 30);
        $Cache->clear_query_lock('top10votes');
    } else {
        $TopVotes = false;
    }
}