Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1241 from ygerasimov/pef-performance
Browse files Browse the repository at this point in the history
PEF: performance enhancement. Load classes selectively.
  • Loading branch information
podarok committed Aug 28, 2018
2 parents d3896c6 + e67eec8 commit 252dbf2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions modules/custom/openy_repeat/src/Controller/RepeatController.php
Expand Up @@ -178,7 +178,13 @@ public function ajaxScheduler( Request $request, $location, $date, $category) {
$result = $query->fetchAll();

$locations_info = $this->getLocationsInfo();
$classes_info = $this->getClassesInfo();

$classesIds = [];
foreach ($result as $key => $item) {
$classesIds[$item->class] = $item->class;
}
$classes_info = $this->getClassesInfo($classesIds);

foreach ($result as $key => $item) {
$result[$key]->location_info = $locations_info[$item->location];
$result[$key]->class_info = $classes_info[$item->class];
Expand Down Expand Up @@ -259,18 +265,14 @@ public function getLocationsInfo() {
/**
* Get detailed info about Class.
*/
public function getClassesInfo() {
public function getClassesInfo($nids) {
$data = [];
$tags = ['node_list'];
$cid = 'openy_repeat:classes_info';
$tags = [];
$cid = 'openy_repeat:classes_info' . md5(json_encode($nids));
if ($cache = $this->cache->get($cid)) {
$data = $cache->data;
}
else {
$nids = $this->entityQuery
->get('node')
->condition('type','class')
->execute();
$nids_chunked = array_chunk($nids, 20, TRUE);
foreach ($nids_chunked as $chunk) {
$classes = $this->entityTypeManager->getStorage('node')->loadMultiple($chunk);
Expand Down

0 comments on commit 252dbf2

Please sign in to comment.