Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Avoid large mysql packages on statbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed May 13, 2016
1 parent 9c4a3c6 commit ffb4350
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions includes/classes/class.statbuilder.php
Expand Up @@ -278,7 +278,10 @@ final public function MakeStats()
$UserPoints = array();
$TotalData = $this->GetUsersInfosFromDB();
$FinalSQL = 'TRUNCATE TABLE %%STATPOINTS%%;';
$FinalSQL .= "INSERT INTO %%STATPOINTS%% (id_owner, id_ally, stat_type, universe, tech_old_rank, tech_points, tech_count, build_old_rank, build_points, build_count, defs_old_rank, defs_points, defs_count, fleet_old_rank, fleet_points, fleet_count, total_old_rank, total_points, total_count) VALUES ";

$tableHeader = "INSERT INTO %%STATPOINTS%% (id_owner, id_ally, stat_type, universe, tech_old_rank, tech_points, tech_count, build_old_rank, build_points, build_count, defs_old_rank, defs_points, defs_count, fleet_old_rank, fleet_points, fleet_count, total_old_rank, total_points, total_count) VALUES ";

$FinalSQL .= $tableHeader;

foreach($TotalData['Planets'] as $PlanetData)
{
Expand All @@ -295,8 +298,11 @@ final public function MakeStats()

$UniData = array();

$i = 0;

foreach($TotalData['Users'] as $UserData)
{
$i++;
if(!isset($UniData[$UserData['universe']]))
$UniData[$UserData['universe']] = 0;

Expand Down Expand Up @@ -381,13 +387,20 @@ final public function MakeStats()
(isset($UserData['old_total_rank']) ? $UserData['old_total_rank'] : 0).", ".
(isset($UserPoints[$UserData['id']]['total']['points']) ? min($UserPoints[$UserData['id']]['total']['points'], 1E50) : 0).", ".
(isset($UserPoints[$UserData['id']]['total']['count']) ? $UserPoints[$UserData['id']]['total']['count'] : 0)."), ";

if ($i >= 50) {
$FinalSQL = substr($FinalSQL, 0, -2).';';
$this->SaveDataIntoDB($FinalSQL);
$FinalSQL = $tableHeader;
}
}

if !empty($FinalSQL) {
$FinalSQL = substr($FinalSQL, 0, -2).';';
$this->SaveDataIntoDB($FinalSQL);
unset($UserPoints);
}

$FinalSQL = substr($FinalSQL, 0, -2).';';

$this->SaveDataIntoDB($FinalSQL);
unset($UserPoints);

if(count($AllyPoints) != 0)
{
$AllySQL = "INSERT INTO %%STATPOINTS%% (id_owner, id_ally, stat_type, universe, tech_old_rank, tech_points, tech_count, build_old_rank, build_points, build_count, defs_old_rank, defs_points, defs_count, fleet_old_rank, fleet_points, fleet_count, total_old_rank, total_points, total_count) VALUES ";
Expand Down

6 comments on commit ffb4350

@Jbaukens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello what do you mean with this commit adding some limits ?

Regards

@jkroepke
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have 1000 players, statbuilder collects alle data an send one big query with all data.

This update will send queries every 50 player to avoid big querys, stats works now without a the requirement of a high vaule max packet size ...

@Jbaukens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes thats what i though i wanted to be sure, will be great since i reached 2.900 players registered
also last question for that one will it affect the time it takes to run or no ? i mean will it take longer then sending a big data packet ?

@jkroepke
Copy link
Owner Author

@jkroepke jkroepke commented on ffb4350 May 20, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terassiel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error from cronjob:
USER ERROR: "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
in : includes/classes/Database.class.php | Line: 198
Stack trace:
#0 /includes/classes/Database.class.php(198): PDO->query('INSERT INTO un...')
#1 /includes/classes/class.statbuilder.php(158): Database->nativeQuery('INSERT INTO %%...')
#2 /includes/classes/class.statbuilder.php(400): statbuilder->SaveDataIntoDB('INSERT INTO %%...')
#3 /includes/classes/cronjob/StatisticCronjob.class.php(38): statbuilder->MakeStats()
#4 /includes/classes/Cronjob.class.php(68): StatisticCronjob->run()
#5 /cronjob.php(65): Cronjob::execute(2)

Error from manual update:
USER ERROR: "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
in: includes/classes/Database.class.php | Line: 198
Stack trace:
#0 /includes/classes/Database.class.php(198): PDO->query('INSERT INTO un...')
#1 /includes/classes/class.statbuilder.php(158): Database->nativeQuery('INSERT INTO %%...')
#2 /includes/classes/class.statbuilder.php(400): statbuilder->SaveDataIntoDB('INSERT INTO %%...')
#3 /includes/pages/adm/ShowStatUpdatePage.php(35): statbuilder->MakeStats()
#4 /admin.php(154): ShowStatUpdatePage()

@Jbaukens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had the same problem jan...

Regards

Please sign in to comment.