]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #4926: prefetches entities to be displayed in river
authorSteve Clay <steve@mrclay.org>
Thu, 22 Nov 2012 03:25:18 +0000 (22:25 -0500)
committerSteve Clay <steve@mrclay.org>
Thu, 22 Nov 2012 03:25:18 +0000 (22:25 -0500)
engine/lib/river.php

index b717a7756cfce31f4f64895213b367d2b0077dff..7bc3af9def0442107f0a1003433e63a638cbf6b0 100644 (file)
@@ -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 {
@@ -369,12 +370,46 @@ 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) {
+               $guids[$item->object_guid] = true;
+               $guids[$item->subject_guid] = true;
+               if (count($guids) > 100) {
+                       break;
+               }
+       }
+       // return value unneeded, just priming cache
+       elgg_get_entities(array('guids' => array_keys($guids)));
+
+       // prefetch object containers
+       $guids = array();
+       foreach ($river_items as $item) {
+               $object = $item->getObjectEntity();
+               if ($object) {
+                       $guids[$object->container_guid] = true;
+               }
+               if (count($guids) > 100) {
+                       break;
+               }
+       }
+       // return value unneeded, just priming cache
+       elgg_get_entities(array('guids' => array_keys($guids)));
+}
+
 /**
  * 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
  */