Skip to content

Commit c75aa0a

Browse files
authored
Minor optimisations to Archiving (matomo-org#18156)
1 parent 6b41189 commit c75aa0a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

core/DataTable/Row.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ private function isSummableColumn($columnName)
473473
*/
474474
public function sumRow(Row $rowToSum, $enableCopyMetadata = true, $aggregationOperations = false)
475475
{
476+
$operationsIsArray = is_array($aggregationOperations);
476477
foreach ($rowToSum as $columnToSumName => $columnToSumValue) {
477478
if (!$this->isSummableColumn($columnToSumName)) {
478479
continue;
@@ -481,11 +482,12 @@ public function sumRow(Row $rowToSum, $enableCopyMetadata = true, $aggregationOp
481482
$thisColumnValue = $this->getColumn($columnToSumName);
482483

483484
$operation = 'sum';
484-
if (is_array($aggregationOperations) && isset($aggregationOperations[$columnToSumName])) {
485-
if (is_string($aggregationOperations[$columnToSumName])) {
486-
$operation = strtolower($aggregationOperations[$columnToSumName]);
487-
} elseif (is_callable($aggregationOperations[$columnToSumName])) {
488-
$operation = $aggregationOperations[$columnToSumName];
485+
if ($operationsIsArray && isset($aggregationOperations[$columnToSumName])) {
486+
$operationName = $aggregationOperations[$columnToSumName];
487+
if (is_string($operationName)) {
488+
$operation = strtolower($operationName);
489+
} elseif (is_callable($operationName)) {
490+
$operation = $operationName;
489491
}
490492
}
491493

@@ -650,6 +652,10 @@ public function setComparisons(DataTable $table)
650652
*/
651653
protected function sumRowArray($thisColumnValue, $columnToSumValue, $columnName = null)
652654
{
655+
if ($columnToSumValue === false) {
656+
return $thisColumnValue;
657+
}
658+
653659
if (is_numeric($columnToSumValue)) {
654660
if ($thisColumnValue === false) {
655661
$thisColumnValue = 0;
@@ -664,10 +670,6 @@ protected function sumRowArray($thisColumnValue, $columnToSumValue, $columnName
664670
return $thisColumnValue + $columnToSumValue;
665671
}
666672

667-
if ($columnToSumValue === false) {
668-
return $thisColumnValue;
669-
}
670-
671673
if ($thisColumnValue === false) {
672674
return $columnToSumValue;
673675
}

0 commit comments

Comments
 (0)