Skip to content

Commit

Permalink
Use capped values in archiver and metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rr-it committed Jul 4, 2023
1 parent 56e94d6 commit cf27b5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 6 additions & 3 deletions plugins/PagePerformance/Archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\PagePerformance;

use Piwik\Plugins\PagePerformance\Columns\Base;
use Piwik\Plugins\PagePerformance\Columns\TimeDomCompletion;
use Piwik\Plugins\PagePerformance\Columns\TimeDomProcessing;
use Piwik\Plugins\PagePerformance\Columns\TimeNetwork;
Expand Down Expand Up @@ -41,7 +42,9 @@ public function aggregateDayReport()
$selects = $totalColumns = $hitsColumns = $allColumns = [];
$table = 'log_link_visit_action';


/**
* @var Base[] $performanceDimensions
*/
$performanceDimensions = [
new TimeNetwork(),
new TimeServer(),
Expand All @@ -53,9 +56,9 @@ public function aggregateDayReport()

foreach($performanceDimensions as $dimension) {
$column = $dimension->getColumnName();
$selects[] = "sum($table.$column) as {$column}_total";
$selects[] = "sum(" . sprintf($dimension->getSqlCappedValue(), $table . '.' . $column) . ") as {$column}_total";
$selects[] = "sum(if($table.$column is null, 0, 1)) as {$column}_hits";
$totalColumns[] = "IFNULL($table.$column,0)";
$totalColumns[] = sprintf($dimension->getSqlCappedValue(), $table . '.' . $column);
$hitsColumns[] = "if($table.$column is null, 0, 1)";
$allColumns[] = "$table.$column";
}
Expand Down
11 changes: 3 additions & 8 deletions plugins/PagePerformance/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Piwik\Plugins\PagePerformance;

use Piwik\Columns\Dimension;
use Piwik\Plugin\Dimension\ActionDimension;
use Piwik\Plugins\PagePerformance\Columns\Base;
use Piwik\Plugins\PagePerformance\Columns\Metrics\AveragePageLoadTime;
use Piwik\Plugins\PagePerformance\Columns\Metrics\AverageTimeDomCompletion;
use Piwik\Plugins\PagePerformance\Columns\Metrics\AverageTimeDomProcessing;
Expand Down Expand Up @@ -97,7 +97,7 @@ public static function attachActionMetrics(&$metricsConfig)
$table = 'log_link_visit_action';

/**
* @var ActionDimension[] $performanceDimensions
* @var Base[] $performanceDimensions
*/
$performanceDimensions = [
new TimeNetwork(),
Expand All @@ -112,12 +112,7 @@ public static function attachActionMetrics(&$metricsConfig)
$column = $table . '.' . $id;
$metricsConfig['sum_'.$id] = [
'aggregation' => 'sum',
'query' => "sum(
case when " . $column . " is null
then 0
else " . $column . "
end
) / 1000"
'query' => "sum(" . sprintf($dimension->getSqlCappedValue(), $column) . ") / 1000"
];
$metricsConfig['nb_hits_with_'.$id] = [
'aggregation' => 'sum',
Expand Down

0 comments on commit cf27b5f

Please sign in to comment.