Elgg
Version 5.0
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
Elgg
EntityPreloader.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg
;
4
5
use
Elgg\Database\EntityTable
;
6
use
Elgg\Database\Entities
;
7
use
Elgg\Cache\EntityCache
;
8
14
class
EntityPreloader
{
15
20
public
$_callable_cache_checker
;
21
26
public
$_callable_entity_loader
;
27
33
public
function
__construct
(
EntityTable
$entity_table) {
34
$this->_callable_cache_checker =
function
(
$guid
) use ($entity_table) {
35
return
$entity_table->
getFromCache
(
$guid
);
36
};
37
$this->_callable_entity_loader =
function
(
$options
) {
38
return
Entities::find(
$options
);
39
};
40
}
41
51
public
function
preload
($objects, array $guid_properties) {
52
$guids
= $this->getGuidsToLoad($objects, $guid_properties);
53
54
// If only 1 to load, not worth the overhead of elgg_get_entities(),
55
// get_entity() will handle it later.
56
if
(
count
(
$guids
) > 1) {
57
call_user_func($this->_callable_entity_loader, [
58
'guids'
=>
$guids
,
59
'limit'
=> EntityCache::MAX_SIZE,
60
'order_by'
=>
false
,
61
]);
62
}
63
}
64
75
protected
function
getGuidsToLoad
($objects, array $guid_properties) {
76
if
(!is_array($objects) ||
count
($objects) < 2) {
77
return
[];
78
}
79
80
$preload_guids = [];
81
foreach
($objects as
$object
) {
82
if
(is_object($object)) {
83
foreach
($guid_properties as $property) {
84
if
(empty($object->{$property})) {
85
continue
;
86
}
87
88
$guid
= $object->{$property};
89
if
(
$guid
&& !call_user_func($this->_callable_cache_checker,
$guid
)) {
90
$preload_guids[] =
$guid
;
91
}
92
}
93
}
94
}
95
96
return
array_unique($preload_guids);
97
}
98
}
Elgg\Database\EntityTable\getFromCache
getFromCache(int $guid)
Get an entity from the in-memory or memcache caches.
Definition:
EntityTable.php:244
EntityCache
count
$options
$options
Elgg admin footer.
Definition:
footer.php:6
EntityTable
Elgg
Definition:
ActionsService.php:3
Elgg\EntityPreloader\$_callable_cache_checker
$_callable_cache_checker
Definition:
EntityPreloader.php:20
Elgg\EntityPreloader\$_callable_entity_loader
$_callable_entity_loader
Definition:
EntityPreloader.php:26
Elgg\EntityPreloader\getGuidsToLoad
getGuidsToLoad($objects, array $guid_properties)
Get GUIDs that need to be loaded.
Definition:
EntityPreloader.php:75
$guids
$guids
Activates all specified installed and inactive plugins.
Definition:
activate_all.php:9
$object
if($email instanceof\Elgg\Email) $object
Definition:
body.php:24
Elgg\EntityPreloader\preload
preload($objects, array $guid_properties)
Preload entities based on the given objects.
Definition:
EntityPreloader.php:51
Elgg\EntityPreloader
Preload entities based on properties of fetched objects.
Definition:
EntityPreloader.php:14
Elgg\EntityPreloader\__construct
__construct(EntityTable $entity_table)
Constructor.
Definition:
EntityPreloader.php:33
Entities
Elgg\Database\EntityTable
Entity table database service.
Definition:
EntityTable.php:26
$guid
$guid
Reset an ElggUpgrade.
Definition:
reset.php:6
Generated on Thu Sep 21 2023 00:00:18 for Elgg by
1.8.11