Skip to content

Commit 9a3e16b

Browse files
committed
Remove no longer needed double rollup result iteration
1 parent b7acb0d commit 9a3e16b

2 files changed

Lines changed: 50 additions & 85 deletions

File tree

plugins/CustomDimensions/RecordBuilders/CustomDimension.php

Lines changed: 32 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -186,100 +186,65 @@ protected function aggregateFromActions(DataTable $report, LogAggregator $logAgg
186186
$metricIds[] = Metrics::INDEX_BOUNCE_COUNT;
187187
$metricIds[] = Metrics::INDEX_PAGE_EXIT_NB_VISITS;
188188

189-
$actionRows = [];
190-
191189
while ($row = $resultSet->fetch()) {
192190
if (!isset($row[Metrics::INDEX_NB_VISITS])) {
193191
return;
194192
}
195193

196194
$label = $row[$valueField];
197195

198-
if ($withRollup) {
199-
$url = $row['url'];
200-
201-
if (is_null($label)) {
202-
continue;
203-
}
204-
205-
if (!is_null($url)) {
206-
$actionRows[] = $row;
207-
continue;
208-
}
196+
if ($withRollup && $label === null) {
197+
// top-level rollup result
198+
continue;
209199
}
210200

211201
$columns = [];
202+
212203
foreach ($metricIds as $id) {
213204
$columns[$id] = (float) ($row[$id] ?? 0);
214205
}
206+
215207
$label = $this->cleanCustomDimensionValue($label);
216-
$tableRow = $report->sumRowWithLabel($label, $columns);
208+
$url = $row['url'];
217209

218210
if (!$withRollup) {
219-
$url = $row['url'];
220-
if (empty($url)) {
221-
continue;
222-
}
223-
224-
// make sure we always work with normalized URL no matter how the individual action stores it
225-
$normalized = Tracker\PageUrl::normalizeUrl($url);
226-
$url = $normalized['url'];
227-
228-
if (empty($url)) {
229-
continue;
230-
}
231-
232-
$tableRow->sumRowWithLabelToSubtable($url, $columns);
233-
}
234-
}
235-
236-
if ($withRollup) {
237-
$previousLabel = null;
238-
239-
foreach ($actionRows as $row) {
240-
if (!isset($row[Metrics::INDEX_NB_VISITS])) {
241-
return;
242-
}
243-
244-
$label = $row[$valueField];
245-
$url = $row['url'];
246-
247-
if (is_null($label) || is_null($url)) {
211+
$tableRow = $report->sumRowWithLabel($label, $columns);
212+
} else {
213+
if ($url === null) {
214+
// second-level rollup result
215+
$report->sumRowWithLabel($label, $columns);
248216
continue;
249217
}
250218

251-
$label = $this->cleanCustomDimensionValue($label);
252219
$tableRow = $report->getRowFromLabel($label);
253220

254-
if (empty($tableRow)) {
255-
continue;
256-
}
257-
258-
// make sure we always work with normalized URL no matter how the individual action stores it
259-
$normalized = Tracker\PageUrl::normalizeUrl($url);
260-
$url = $normalized['url'];
261-
262-
if (empty($url)) {
263-
continue;
264-
}
265-
266-
// skip subtable creation if only one "Others" row would appear
267-
if (
268-
$label !== $previousLabel
269-
&& $url === RankingQuery::LABEL_SUMMARY_ROW
270-
) {
221+
if (false === $tableRow) {
222+
// non-rollup row but rollup row is missing
223+
// should not happen, but don't break
271224
continue;
272225
}
226+
}
273227

274-
$previousLabel = $label;
275-
$columns = [];
228+
// make sure we always work with normalized URL no matter how the individual action stores it
229+
$normalized = Tracker\PageUrl::normalizeUrl($url);
230+
$url = $normalized['url'];
276231

277-
foreach ($metricIds as $id) {
278-
$columns[$id] = (float) ($row[$id] ?? 0);
279-
}
232+
if (empty($url)) {
233+
continue;
234+
}
280235

281-
$tableRow->sumRowWithLabelToSubtable($url, $columns);
236+
if (
237+
$withRollup
238+
&& $url === RankingQuery::LABEL_SUMMARY_ROW
239+
&& !$tableRow->isSubtableLoaded()
240+
) {
241+
// skip creating the subtable if:
242+
// - we are using rollups
243+
// - the only row would be "Others"
244+
continue;
282245
}
246+
247+
$tableRow->sumRowWithLabelToSubtable($url, $columns);
283248
}
284249
}
285250

plugins/Referrers/RecordBuilders/AIReferrers.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,40 +88,30 @@ protected function aggregateFromVisits(LogAggregator $logAggregator, DataTable $
8888
{
8989
$resultSet = $this->queryAIReferrerEntryPages($logAggregator, $field);
9090

91-
$actionRows = [];
92-
9391
while ($row = $resultSet->fetch()) {
9492
if (!isset($row[Metrics::INDEX_NB_VISITS])) {
9593
return;
9694
}
9795

9896
$label = $row['referer_name'];
99-
10097
$pageUrlOrTitle = $row['action_name'];
10198

102-
if (is_null($label)) {
99+
if ($label === null) {
100+
// top-level rollup result
103101
continue;
104102
}
105103

106-
if (!is_null($pageUrlOrTitle)) {
107-
$actionRows[] = $row;
104+
if ($pageUrlOrTitle === null) {
105+
// second-level rollup result
106+
$report->sumRowWithLabel($label, $this->makeVisitRow($row));
108107
continue;
109108
}
110109

111-
$report->sumRowWithLabel($label, $this->makeVisitRow($row));
112-
}
113-
114-
foreach ($actionRows as $row) {
115-
if (!isset($row[Metrics::INDEX_NB_VISITS])) {
116-
return;
117-
}
118-
119-
$label = $row['referer_name'];
120-
$pageUrlOrTitle = $row['action_name'];
121-
122110
$tableRow = $report->getRowFromLabel($label);
123111

124-
if (empty($tableRow)) {
112+
if (false === $tableRow) {
113+
// non-rollup row but rollup row is missing
114+
// should not happen, but don't break
125115
continue;
126116
}
127117

@@ -131,6 +121,16 @@ protected function aggregateFromVisits(LogAggregator $logAggregator, DataTable $
131121
$pageUrlOrTitle = $normalized['url'];
132122
}
133123

124+
if (
125+
$pageUrlOrTitle === RankingQuery::LABEL_SUMMARY_ROW
126+
&& !$tableRow->isSubtableLoaded()
127+
) {
128+
// skip creating the subtable if:
129+
// - we are using rollups
130+
// - the only row would be "Others"
131+
continue;
132+
}
133+
134134
$tableRow->sumRowWithLabelToSubtable($pageUrlOrTitle, $this->makeVisitRow($row));
135135
}
136136
}

0 commit comments

Comments
 (0)