Skip to content

Commit 553bb9e

Browse files
committed
TopEdits: fix wikitext output for top projects and simplify queries
I believe I even requested to combine into one query, but inadvertently this put it in the API output as a serialized JSON string. That could be fixed, but this wasn't intended to be there to begin with. Also, combining the queries is only applicable when there is one page of results, which is usually only the case for less prolific users - in which case doing a separate query is negligible. So this just simplifies things.
1 parent 7659310 commit 553bb9e

File tree

3 files changed

+11
-56
lines changed

3 files changed

+11
-56
lines changed

src/Model/TopEdits.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,36 +171,13 @@ public function getNumTopEdits(): int
171171
*/
172172
public function getProjectTotals(int $ns): array
173173
{
174-
if ($this->getNumPagesNamespace() > $this->limit) {
175-
$projectTotals = $this->repository->getProjectTotals(
176-
$this->project,
177-
$this->user,
178-
$ns,
179-
$this->start,
180-
$this->end
181-
);
182-
} else {
183-
$counts_tmp = [];
184-
// List of pages for this namespace
185-
$rows = $this->topEdits[$ns];
186-
foreach ($rows as $row) {
187-
$num = $row["count"];
188-
// May be null or nonexistent for assessment-less pages
189-
$titles = $row["pap_project_title"] ?? "{}";
190-
// Had to use json to pass multiple values in SQL select
191-
foreach (json_decode($titles) as $projectName) {
192-
$counts_tmp[$projectName] ??= 0;
193-
$counts_tmp[$projectName] += $num;
194-
}
195-
}
196-
arsort($counts_tmp);
197-
$counts_tmp = array_slice($counts_tmp, 0, 10);
198-
$projectTotals = [];
199-
foreach ($counts_tmp as $project => $count) {
200-
$projectTotals[] = [ "pap_project_title" => $project, "count" => $count ];
201-
}
202-
}
203-
return $projectTotals;
174+
return $this->repository->getProjectTotals(
175+
$this->project,
176+
$this->user,
177+
$ns,
178+
$this->start,
179+
$this->end
180+
);
204181
}
205182

206183
/**

src/Repository/TopEditsRepository.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ public function getTopEditsNamespace(
122122
LIMIT 1
123123
) AS pa_class"
124124
: '';
125-
$paProjectsTable = $project->getTableName('page_assessments_projects');
126-
$paProjectsSelect = $hasPageAssessments
127-
? ", (
128-
SELECT JSON_ARRAYAGG(pap_project_title)
129-
FROM $paTable
130-
JOIN $paProjectsTable
131-
ON pa_project_id = pap_project_id
132-
WHERE pa_page_id = page_id
133-
) AS pap_project_title"
134-
: '';
135125

136126
$ipcJoin = '';
137127
$whereClause = 'rev_actor = :actorId';
@@ -147,7 +137,6 @@ public function getTopEditsNamespace(
147137
$sql = "SELECT page_namespace AS `namespace`, page_title,
148138
page_is_redirect AS `redirect`, COUNT(page_title) AS `count`
149139
$paSelect
150-
$paProjectsSelect
151140
FROM $pageTable
152141
153142
JOIN $revisionTable ON page_id = rev_page
@@ -309,17 +298,6 @@ public function getTopEditsAllNamespaces(
309298
LIMIT 1
310299
) AS pa_class"
311300
: '';
312-
$paProjectsTable = $project->getTableName('page_assessments_projects');
313-
$paProjectsSelect = $hasPageAssessments
314-
? ", (
315-
SELECT JSON_ARRAYAGG(pap_project_title)
316-
FROM $pageAssessmentsTable
317-
JOIN $paProjectsTable
318-
ON pa_project_id = pap_project_id
319-
WHERE pa_page_id = e.page_id
320-
) AS pap_project_title"
321-
: '';
322-
323301

324302
$ipcJoin = '';
325303
$whereClause = 'rev_actor = :actorId';
@@ -332,7 +310,7 @@ public function getTopEditsAllNamespaces(
332310
}
333311

334312
$sql = "SELECT c.page_namespace AS `namespace`, e.page_title,
335-
c.page_is_redirect AS `redirect`, c.count $paSelect $paProjectsSelect
313+
c.page_is_redirect AS `redirect`, c.count $paSelect
336314
FROM
337315
(
338316
SELECT b.page_namespace, b.page_is_redirect, b.rev_page, b.count

templates/topedits/result_namespace.wikitext.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
|}
4242
{% if showPageAssessment %}
4343
{% set totals = te.projectTotals(ns) %}
44-
{% if totals|keys|length > 0 %}
44+
{% if totals|length > 0 %}
4545
{| class="wikitable sortable"
4646
|+ {{ msg('top-wikiprojects') }}
4747
! {{ msg('wikiproject') }} !! {{ msg('count') }}
48-
{% for wikiproject, count in totals %}
48+
{% for row in totals %}
4949
|-
50-
| {{ wikiproject }} || {{ count|num_format }}
50+
| {{ row.pap_project_title }} || {% verbatim %}{{FORMATNUM:{% endverbatim %}{{ row.count }}}}
5151
{% endfor %}
5252
|}
5353
{% endif %}

0 commit comments

Comments
 (0)