Skip to content

Commit

Permalink
Reports: Optimize SQL query
Browse files Browse the repository at this point in the history
  • Loading branch information
mgbaybay committed Sep 6, 2024
1 parent 625457c commit f515169
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/Report/ProofOfPlay.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ private function getProofOfPlayReportMySql(
$toDt = $toDt->format('U');

// Media on Layouts Ran

// $select = 'SELECT `displaygroup`.`displaygroup`, `displaygroup`.`displayGroupId` from displaygroup';
$select = '
SELECT stat.type,
display.Display,
Expand Down Expand Up @@ -838,23 +840,22 @@ private function getProofOfPlayReportMySql(

$body .= '
GROUP BY stat.type,
stat.tag,
display.Display,
stat.parentCampaignId,
stat.displayId,
stat.campaignId,
layout.layout,
IFNULL(stat.mediaId, stat.widgetId),
IFNULL(`media`.name, IFNULL(`widgetoption`.value, `widget`.type)),
stat.tag,
stat.layoutId,
stat.mediaId,
stat.widgetId,
stat.displayId
stat.tag,
stat.widgetId
';

// Group the data by display group
if ($groupBy === 'displayGroup') {
// Optional groupings
if ($groupBy === 'display') {
$body .= ', display.Display';
} else if ($groupBy === 'displayGroup') {
$body .= ', displaydg.displayGroupId';
}

Expand Down Expand Up @@ -890,12 +891,6 @@ private function getProofOfPlayReportMySql(
$rows[] = $entry;
}

if ($groupBy === 'tag') {
$rows = $this->getByDisplayGroup($rows, 'tag', $displayGroupIds);
} else if ($groupBy === 'displayGroup') {
$rows = $this->getByDisplayGroup($rows, 'displayGroupId', $displayGroupIds);
}

return [
'periodStart' => Carbon::createFromTimestamp($fromDt)->format(DateFormatHelper::getSystemFormat()),
'periodEnd' => Carbon::createFromTimestamp($toDt)->format(DateFormatHelper::getSystemFormat()),
Expand Down

0 comments on commit f515169

Please sign in to comment.