Performance fixes

This commit is contained in:
2026-01-24 20:01:49 -06:00
parent f0e38a4b9c
commit 0752f7e3e3
2 changed files with 21 additions and 13 deletions

View File

@@ -7,7 +7,7 @@
padding-bottom: 0; padding-bottom: 0;
} }
.archive-tree-year { .archive-tree-year {
font-weight: bold; font-weight: normal;
} }
.archive-tree-month { .archive-tree-month {
margin-left: 2em; margin-left: 2em;

View File

@@ -72,17 +72,24 @@ class ArchiveTreeBlock extends BlockBase {
'#markup' => $this->t('No content types selected.'), '#markup' => $this->t('No content types selected.'),
]; ];
} }
// 1. Get node IDs with access check.
$query = $storage->getQuery() $query = $storage->getQuery()
->condition('type', $types, 'IN') ->condition('type', $types, 'IN')
->condition('status', 1) ->condition('status', 1)
->sort('created', 'DESC') ->sort('created', 'DESC')
->accessCheck(TRUE); ->accessCheck(TRUE);
$nids = $query->execute(); $nids = $query->execute();
$nodes = $storage->loadMultiple($nids);
$tree = []; $tree = [];
foreach ($nodes as $node) { if (!empty($nids)) {
$created = $node->getCreatedTime(); // 2. Fetch only nid and created fields for those nodes.
$connection = \Drupal::database();
$result = $connection->select('node_field_data', 'n')
->fields('n', ['nid', 'created'])
->condition('n.nid', $nids, 'IN')
->execute();
foreach ($result as $row) {
$created = $row->created;
$year = date('Y', $created); $year = date('Y', $created);
$month = date('m', $created); $month = date('m', $created);
if (!isset($tree[$year])) { if (!isset($tree[$year])) {
@@ -94,6 +101,7 @@ class ArchiveTreeBlock extends BlockBase {
$tree[$year]['count']++; $tree[$year]['count']++;
$tree[$year]['months'][$month]['count']++; $tree[$year]['months'][$month]['count']++;
} }
}
krsort($tree); // Descending years krsort($tree); // Descending years
foreach ($tree as $year => $data) { foreach ($tree as $year => $data) {