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");
 }
 }
}
asked Jun 4, 2012 at 18:27
\$\endgroup\$
0

1 Answer 1

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' );
answered Jun 4, 2012 at 18:35
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.