Jump to content
MakeWebGames

Recommended Posts

Posted

Anyone know if using the LEAST() function would speed up the 5 mins cron time? since it would reduce the number of querys?

from:

$query="UPDATE users SET brave=brave+((maxbrave/10)+0.5) WHERE brave<maxbrave ";
$query2="UPDATE users SET brave=maxbrave WHERE brave>maxbrave";
$query3="UPDATE users SET hp=hp+(maxhp/3) WHERE hp<maxhp";
$query4="UPDATE users SET hp=maxhp WHERE hp>maxhp";
$db->query($query);
$db->query($query2);
$db->query($query3);
$db->query($query4);

 

to:

$query="UPDATE users SET brave=LEAST((brave+((maxbrave/10)+0.5)),maxbrave) WHERE brave<maxbrave ";
$query2="UPDATE users SET hp=LEAST((hp+(maxhp/3)),maxhp) WHERE hp<maxhp";
$db->query($query);
$db->query($query2);
  • 3 weeks later...
Posted

Re: Cron Optimization question

That looks good to me, I am trying it out.

I also did this:

$db->query("UPDATE users set hospital=hospital-1 WHERE hospital>0");
$db->query("UPDATE users SET jail=jail-1 WHERE jail > 0");
//$hc=$db->num_rows($db->query("SELECT * FROM users WHERE hospital > 0"));
//$jc=$db->num_rows($db->query("SELECT * FROM users WHERE jail > 0"));
//$db->query("UPDATE settings SET conf_value='$hc' WHERE conf_name='hospital_count'");
//$db->query("UPDATE settings SET conf_value='$jc' WHERE conf_name='jail_count'");
$db->query("UPDATE settings SET conf_value=(select count(*) from users where jail > 0) WHERE conf_name='jail_count';");
$db->query("UPDATE settings SET conf_value=(select count(*) from users where hospital > 0) WHERE conf_name='hospital_count';");
Posted

Re: Cron Optimization question

 

That looks good to me, I am trying it out.

I also did this:

$db->query("UPDATE users set hospital=hospital-1 WHERE hospital>0");
$db->query("UPDATE users SET jail=jail-1 WHERE jail > 0");
//$hc=$db->num_rows($db->query("SELECT * FROM users WHERE hospital > 0"));
//$jc=$db->num_rows($db->query("SELECT * FROM users WHERE jail > 0"));
//$db->query("UPDATE settings SET conf_value='$hc' WHERE conf_name='hospital_count'");
//$db->query("UPDATE settings SET conf_value='$jc' WHERE conf_name='jail_count'");
$db->query("UPDATE settings SET conf_value=(select count(*) from users where jail > 0) WHERE conf_name='jail_count';");
$db->query("UPDATE settings SET conf_value=(select count(*) from users where hospital > 0) WHERE conf_name='hospital_count';");

 

I may be missing something here, but when counting / selecting, why are you selecting everything?

Wouldn't selecting one column, also slightly speed your cron execution up?

Posted

Re: Cron Optimization question

For the select using the count(*) function be faster.

then list($count) = mysql_fetch_row($db->query("SELECT count(*) FROM users WHERE hospital > 0"))

count(*) in this context would be counting rows, and would not be operating on individual columns.

For this reason, the spot where count(*) is used, it works out good.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...