Skip to content
This repository was archived by the owner on Dec 6, 2019. It is now read-only.

Commit 215b7f9

Browse files
committed
Optimize the flight time addition calculation
Sum and calculate it directly in SQL
1 parent d3e30a2 commit 215b7f9

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

core/common/StatsData.class.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,14 @@ public static function getMonthsInRange($start, $end)
172172

173173
public static function updateTotalHours()
174174
{
175-
$pireps = PIREPData::findPIREPS(array('p.accepted'=>1));
176-
177-
if(!$pireps)
178-
{
179-
return;
180-
}
181-
182-
$totaltime = 0;
183-
foreach($pireps as $pirep)
184-
{
185-
$totaltime = Util::AddTime($totaltime, $pirep->flighttime);
186-
}
175+
$sql = 'SELECT SEC_TO_TIME(SUM(p.flighttime)) as totaltime
176+
FROM '.TABLE_PREFIX.'pireps p WHERE p.accepted=1';
177+
178+
$total = DB::get_row($sql);
179+
$totaltime = $total->totaltime;
187180

188-
SettingsData::SaveSetting('TOTAL_HOURS', $totaltime);
181+
SettingsData::SaveSetting('TOTAL_HOURS', $totaltime);
182+
return $totaltime;
189183
}
190184

191185
/**
@@ -826,4 +820,4 @@ public static function TotalSchedules($airline_code='')
826820

827821
return $total;
828822
}
829-
}
823+
}

0 commit comments

Comments
 (0)