Elgg
Version 6.3
engine
classes
Elgg
EntityPreloader.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg
;
4
5
use
Elgg\Cache\EntityCache
;
6
use
Elgg\Database\Entities
;
7
13
class
EntityPreloader
{
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
}
$guid
$guid
Reset an ElggUpgrade.
Definition:
reset.php:6
$guids
$guids
Activates all specified installed and inactive plugins.
Definition:
activate_all.php:9
Elgg\Cache\EntityCache
Volatile cache for entities.
Definition:
EntityCache.php:12
Elgg\Database\Entities
Entities repository contains methods for fetching entities from database or performing calculations o...
Definition:
Entities.php:19
Elgg\EntityPreloader
Preload entities based on properties of fetched objects.
Definition:
EntityPreloader.php:13
Elgg\EntityPreloader\__construct
__construct(protected EntityCache $entity_cache)
Constructor.
Definition:
EntityPreloader.php:22
Elgg\EntityPreloader\getGuidsToLoad
getGuidsToLoad(array $objects, array $guid_properties)
Get GUIDs that need to be loaded.
Definition:
EntityPreloader.php:58
Elgg\EntityPreloader\preload
preload(array $objects, array $guid_properties)
Preload entities based on the given objects.
Definition:
EntityPreloader.php:34
$object
if($email instanceof \Elgg\Email) $object
Definition:
body.php:24
Elgg
Definition:
ActionsService.php:3
if
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition:
robots.php:10
Generated on Sun Sep 7 2025 00:00:22 for Elgg by
1.9.1