Skip to content

Commit f9d261c

Browse files
committed
try using with rollup again
1 parent bf6164b commit f9d261c

1 file changed

Lines changed: 17 additions & 27 deletions

File tree

plugins/BotTracking/RecordBuilders/AIAssistantReports.php

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ private function populateTableForActionType(array $tables, int $actionType, LogA
146146
{
147147
$resultSet = $this->queryBotRequests($logAggregator, $actionType);
148148
$actionRows = [];
149-
$botTotals = [];
150149

151150
while ($row = $resultSet->fetch()) {
152151
/**
@@ -159,28 +158,18 @@ private function populateTableForActionType(array $tables, int $actionType, LogA
159158
continue;
160159
}
161160

162-
if (is_null($url)) {
161+
if (!is_null($url)) {
162+
$actionRows[] = $row;
163163
continue;
164164
}
165165

166-
$actionRows[] = $row;
166+
$metrics = [
167+
Metrics::COLUMN_REQUESTS => $row['requests'],
168+
Metrics::COLUMN_DOCUMENT_REQUESTS => $actionType === Action::TYPE_DOWNLOAD ? $row['requests'] : 0,
169+
Metrics::COLUMN_PAGE_REQUESTS => $actionType === Action::TYPE_PAGE_URL ? $row['requests'] : 0,
170+
Metrics::COLUMN_ACQUIRED_VISITS => $visits[$label] ?? 0,
171+
];
167172

168-
if (!isset($botTotals[$label])) {
169-
$botTotals[$label] = [
170-
Metrics::COLUMN_REQUESTS => 0,
171-
Metrics::COLUMN_DOCUMENT_REQUESTS => 0,
172-
Metrics::COLUMN_PAGE_REQUESTS => 0,
173-
Metrics::COLUMN_ACQUIRED_VISITS => 0,
174-
];
175-
}
176-
177-
$botTotals[$label][Metrics::COLUMN_REQUESTS] += $row['requests'];
178-
$botTotals[$label][Metrics::COLUMN_DOCUMENT_REQUESTS] += $actionType === Action::TYPE_DOWNLOAD ? $row['requests'] : 0;
179-
$botTotals[$label][Metrics::COLUMN_PAGE_REQUESTS] += $actionType === Action::TYPE_PAGE_URL ? $row['requests'] : 0;
180-
$botTotals[$label][Metrics::COLUMN_ACQUIRED_VISITS] = max($botTotals[$label][Metrics::COLUMN_ACQUIRED_VISITS], $visits[$label] ?? 0);
181-
}
182-
183-
foreach ($botTotals as $label => $metrics) {
184173
$tables[Archiver::AI_ASSISTANTS_PAGES_RECORD]->sumRowWithLabel($label, $metrics, [Metrics::COLUMN_ACQUIRED_VISITS => 'max']);
185174
$tables[Archiver::AI_ASSISTANTS_DOCUMENTS_RECORD]->sumRowWithLabel($label, $metrics, [Metrics::COLUMN_ACQUIRED_VISITS => 'max']);
186175
}
@@ -222,27 +211,28 @@ private function populateTableForActionType(array $tables, int $actionType, LogA
222211
private function queryBotRequests(LogAggregator $logAggregator, int $actionType)
223212
{
224213
$where = $logAggregator->getWhereStatement('bot', 'server_time');
225-
$where .= ' AND log_action.name IS NOT NULL
226-
AND log_action.name <> \'\'
227-
AND log_action.type = ' . $actionType;
228214

229215
$sql = sprintf(
230-
"SELECT bot.bot_name, log_action.name AS url, COUNT(*) AS requests
216+
"SELECT * FROM (SELECT bot.bot_name, log_action.name AS url, COUNT(*) AS requests
231217
FROM %s AS bot
232218
INNER JOIN %s AS log_action ON log_action.idaction = bot.idaction_url
233-
WHERE %s
234-
GROUP BY bot.bot_name, url
235-
ORDER BY bot.bot_name, requests DESC, url",
219+
WHERE log_action.name IS NOT NULL
220+
AND log_action.name <> ''
221+
AND log_action.type = %d
222+
AND %s
223+
GROUP BY bot.bot_name, url WITH ROLLUP) AS rollupQuery
224+
ORDER BY bot_name, requests DESC, url",
236225
BotRequestsDao::getPrefixedTableName(),
237226
Common::prefixTable('log_action'),
227+
$actionType,
238228
$where
239229
);
240230

241231
if ($this->rankingQueryLimit > 0) {
242232
$rankingQuery = new RankingQuery($this->rankingQueryLimit);
243233
$rankingQuery->addLabelColumn(['bot_name', 'url']);
244234
$rankingQuery->addColumn('requests', 'sum');
245-
$sql = $rankingQuery->generateRankingQuery($sql);
235+
$sql = $rankingQuery->generateRankingQuery($sql, true);
246236
}
247237

248238
return Db::query($sql, $logAggregator->getGeneralQueryBindParams());

0 commit comments

Comments
 (0)