@@ -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
0 commit comments