Skip to content

Commit fa8ea41

Browse files
committed
dashboard: optimize DB access
1 parent d55b115 commit fa8ea41

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

db.php

+16
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,22 @@ function db_get_patch_stats() {
282282
->getArrayResult();
283283
}
284284

285+
function db_get_pr_stats($year) {
286+
global $entityManager;
287+
return $entityManager->createQueryBuilder()
288+
->from('Patch', 'p')
289+
->select(['p.status',
290+
'p.type',
291+
'g.repository',
292+
'COUNT(p.status) AS count'])
293+
->join('p.group', 'g')
294+
->where('g.year = :year')
295+
->groupBy('p.status, p.type, g.repository')
296+
->setParameter('year', $year)
297+
->getQuery()
298+
->getArrayResult();
299+
}
300+
285301
function db_delete_cache() {
286302
global $connection;
287303
$connection->executeStatement('DROP TABLE IF EXISTS cache_items');

pages/dashboard.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@
7373
@++$projs[$repo->name()];
7474

7575
$prs_per_project[$repo->name()]['url'] = (string)$repo;
76-
foreach ($group->patches as $patch) {
77-
@++$prs_per_project[$repo->name()][$patch->type][$patch->wasMerged()];
78-
}
7976
}
8077
}
8178

79+
foreach (db_get_pr_stats($selected_year) as $data) {
80+
$repo = (new Repository($data['repository']))->name();
81+
$merged = $data['status'] == PATCH_MERGED ||
82+
$data['status'] == PATCH_MERGED_ILLEGAL;
83+
@$prs_per_project[$repo][$data['type']][$merged] += $data['count'];
84+
}
85+
8286
if (sizeof($projs) > 10) {
8387
foreach ($projs as $proj => $n) {
8488
if ($n == 1)

0 commit comments

Comments
 (0)