summaryrefslogtreecommitdiffstats
path: root/include/functions.php
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2012-02-18 23:13:23 -0800
committerArun Persaud <apersaud@lbl.gov>2012-02-18 23:18:05 -0800
commit72842383a6162e43f8b9630bfcca13d10eca7bff (patch)
tree89aa18a5bf6f36109d8244ca926484ebdbb04c03 /include/functions.php
parentcc143e38299d3dd3981efd81972c0e0df4df1462 (diff)
downloade-DoKo-72842383a6162e43f8b9630bfcca13d10eca7bff.tar.gz
e-DoKo-72842383a6162e43f8b9630bfcca13d10eca7bff.tar.bz2
e-DoKo-72842383a6162e43f8b9630bfcca13d10eca7bff.zip
speed up get score table
instead of looping over all games and have 3 database querries for each gameid, we now only do 5 querries: one for the gameids, scores and gametype and then one for each player to get his party
Diffstat (limited to 'include/functions.php')
-rw-r--r--include/functions.php35
1 files changed, 20 insertions, 15 deletions
diff --git a/include/functions.php b/include/functions.php
index c8def33..a17ce08 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1265,28 +1265,33 @@ function generate_score_table($session)
$score = array();
$i=0;
- /* get all ids */
+ /* get all ids, scores and gametypes */
$gameids = DB_get_gameids_of_finished_games_by_session($session);
if($gameids == NULL)
return $score;
- /* get player id, names... from the first game */
$player = array();
- $result = DB_query("SELECT User.id, User.fullname from Hand".
- " LEFT JOIN User On Hand.user_id=User.id".
- " WHERE Hand.game_id=".$gameids[0]);
+ $player_party = array();
+
+ /* get player id from the first game */
+ $result = DB_query("SELECT user_id from Hand".
+ " WHERE Hand.game_id=".$gameids[0][0]);
while( $r = DB_fetch_array($result))
$player[$r[0]] = 0;
+ /* get party of players for each game in the session */
+ foreach($player as $id=>$points)
+ $player_party[$id]=DB_get_party_by_session_and_userid($session,$id);
+
/* get points and generate table */
foreach($gameids as $gameid)
{
- $re_score = DB_get_score_by_gameid($gameid);
- $gametype = DB_get_gametype_by_gameid($gameid);
+ $re_score = $gameid[1];
+ $gametype = $gameid[2];
foreach($player as $id=>$points)
{
- $party = DB_get_party_by_gameid_and_userid($gameid,$id);
+ $party = $player_party[$id][$i][0];
if($party == "re")
if($gametype=="solo")
$player[$id] += 3*$re_score;
@@ -1295,7 +1300,7 @@ function generate_score_table($session)
else if ($party == "contra")
$player[$id] -= $re_score;
}
- $score[$i]['gameid'] = $gameid ;
+ $score[$i]['gameid'] = $gameid[0] ;
$score[$i]['players'] = $player;
$score[$i]['points'] = abs($re_score);
$score[$i]['solo'] = ($gametype=="solo");
@@ -1310,14 +1315,14 @@ function generate_global_score_table()
{
$return = array();
- /* get all ids */
+ /* get all ids, scores and gametypes */
$gameids = DB_get_gameids_of_finished_games_by_session(0);
if($gameids == NULL)
return '';
- /* get player id, names... from the User table */
$player = array();
+ /* get player id, names... from the User table */
$result = DB_query('SELECT User.id, User.fullname FROM User');
/* save information in an array */
@@ -1328,15 +1333,15 @@ function generate_global_score_table()
/* get points and generate table */
foreach($gameids as $gameid)
{
- $re_score = DB_get_score_by_gameid($gameid);
- $gametype = DB_get_gametype_by_gameid($gameid);
+ $re_score = $gameid[1];
+ $gametype = $gameid[2];
/* get players involved in this game */
- $result = DB_query('SELECT user_id FROM Hand WHERE game_id='.DB_quote_smart($gameid));
+ $result = DB_query('SELECT user_id FROM Hand WHERE game_id='.DB_quote_smart($gameid[0]));
while($r = DB_fetch_array($result))
{
$id = $r[0];
- $party = DB_get_party_by_gameid_and_userid($gameid,$id);
+ $party = DB_get_party_by_gameid_and_userid($gameid[0],$id);
if($party == 're')
if($gametype=='solo')
$player[$id]['points'] += 3*$re_score;