1
\$\begingroup\$

I have this function takes a long time to complete. Is there a way i can improve it to quicken the procedure

function do_updatebonus() {
    global $site_config;

    $res200 = SQL_Query_exec("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'");

    while ($row200 = mysql_fetch_assoc($res200)) {
        $userid = $row200["userid"];
        $res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND userid = $userid");

        $c = mysql_result($res201, 0);
        if ($c >= 5) {
            SQL_Query_exec("UPDATE users SET seedbonus = seedbonus + '" . $site_config["bonuspertime"] . "' WHERE id = $userid");
        }
    }
}
\$\endgroup\$
1
\$\begingroup\$

Yeah, you can optimize your query,

 $res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND userid = $userid");

As this query will first check for seeder which has 'yes' and then for userid. So you can first check for userid, then for seeder. This will improve performance

$res201 = SQL_Query_exec("SELECT COUNT(torrent) FROM peers WHERE userid = $userid" AND seeder = 'yes' );
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.