Elgg  Version master
EntityPreloader.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
7 
14 
15  const MAX_PRELOAD = 256;
16 
22  public function __construct(protected EntityCache $entity_cache) {
23  }
24 
34  public function preload(array $objects, array $guid_properties): void {
35  $guids = $this->getGuidsToLoad($objects, $guid_properties);
36 
37  // If only 1 to load, not worth the overhead of elgg_get_entities(),
38  // get_entity() will handle it later.
39  if (count($guids) > 1) {
40  Entities::find([
41  'guids' => $guids,
42  'limit' => self::MAX_PRELOAD,
43  'order_by' => false,
44  ]);
45  }
46  }
47 
58  protected function getGuidsToLoad(array $objects, array $guid_properties): array {
59  if (count($objects) < 2) {
60  return [];
61  }
62 
63  $preload_guids = [];
64  foreach ($objects as $object) {
65  if (!is_object($object)) {
66  continue;
67  }
68 
69  foreach ($guid_properties as $property) {
70  if (empty($object->{$property})) {
71  continue;
72  }
73 
74  $guid = (int) $object->{$property};
75  if ($guid && is_null($this->entity_cache->load($guid))) {
76  $preload_guids[] = $guid;
77  }
78  }
79  }
80 
81  return array_unique($preload_guids);
82  }
83 }
__construct(protected EntityCache $entity_cache)
Constructor.
getGuidsToLoad(array $objects, array $guid_properties)
Get GUIDs that need to be loaded.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
preload(array $objects, array $guid_properties)
Preload entities based on the given objects.
Volatile cache for entities.
Definition: EntityCache.php:12
$guids
Activates all specified installed and inactive plugins.
Definition: activate_all.php:9
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
Preload entities based on properties of fetched objects.
$guid
Reset an ElggUpgrade.
Definition: reset.php:6