aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorSteve Clay <steve@mrclay.org>2012-11-28 16:23:12 -0800
committerSteve Clay <steve@mrclay.org>2012-11-28 16:23:12 -0800
commit2ac189cb0ab26c10e7feda980402d54e5b6dbf3e (patch)
treeb259f259c66ee7e38026fce8caffe09c843d91f5 /engine/lib
parent7f8354496e76a4de6c73b7ee5e27061b2fec6143 (diff)
parent3a3027ac4bf011873a8b08d56c19fa1379cd0a07 (diff)
downloadelgg-2ac189cb0ab26c10e7feda980402d54e5b6dbf3e.tar.gz
elgg-2ac189cb0ab26c10e7feda980402d54e5b6dbf3e.tar.bz2
Merge pull request #442 from mrclay/4926-18-riverfetch
Fixes #4926: prefetches entities to be displayed in river
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/river.php48
1 files changed, 47 insertions, 1 deletions
diff --git a/engine/lib/river.php b/engine/lib/river.php
index b717a7756..33f34360e 100644
--- a/engine/lib/river.php
+++ b/engine/lib/river.php
@@ -361,6 +361,7 @@ function elgg_get_river(array $options = array()) {
}
$river_items = get_data($query, 'elgg_row_to_elgg_river_item');
+ _elgg_prefetch_river_entities($river_items);
return $river_items;
} else {
@@ -370,11 +371,56 @@ function elgg_get_river(array $options = array()) {
}
/**
+ * Prefetch entities that will be displayed in the river.
+ *
+ * @param ElggRiverItem[] $river_items
+ * @access private
+ */
+function _elgg_prefetch_river_entities(array $river_items) {
+ // prefetch objects and subjects
+ $guids = array();
+ foreach ($river_items as $item) {
+ if ($item->subject_guid && !retrieve_cached_entity($item->subject_guid)) {
+ $guids[$item->subject_guid] = true;
+ }
+ if ($item->object_guid && !retrieve_cached_entity($item->object_guid)) {
+ $guids[$item->object_guid] = true;
+ }
+ }
+ if ($guids) {
+ // avoid creating oversized query
+ // @todo how to better handle this?
+ $guids = array_slice($guids, 0, 300, true);
+ // return value unneeded, just priming cache
+ elgg_get_entities(array(
+ 'guids' => array_keys($guids),
+ 'limit' => 0,
+ ));
+ }
+
+ // prefetch object containers
+ $guids = array();
+ foreach ($river_items as $item) {
+ $object = $item->getObjectEntity();
+ if ($object->container_guid && !retrieve_cached_entity($object->container_guid)) {
+ $guids[$object->container_guid] = true;
+ }
+ }
+ if ($guids) {
+ $guids = array_slice($guids, 0, 300, true);
+ elgg_get_entities(array(
+ 'guids' => array_keys($guids),
+ 'limit' => 0,
+ ));
+ }
+}
+
+/**
* List river items
*
* @param array $options Any options from elgg_get_river() plus:
* pagination => BOOL Display pagination links (true)
-
+ *
* @return string
* @since 1.8.0
*/