aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggBatch.php
diff options
context:
space:
mode:
authorSteve Clay <steve@mrclay.org>2013-06-08 21:34:11 -0400
committerSteve Clay <steve@mrclay.org>2013-06-08 21:34:11 -0400
commit8a47b2342e53c9cdf3093982486b19d6cc2f3e9b (patch)
tree38580c9ead3830e100da483f4e21d9198b9f8bc3 /engine/classes/ElggBatch.php
parent3a3a520958e1eb31ac9d20e7cb818d8c3b5fff4a (diff)
downloadelgg-8a47b2342e53c9cdf3093982486b19d6cc2f3e9b.tar.gz
elgg-8a47b2342e53c9cdf3093982486b19d6cc2f3e9b.tar.bz2
Improved algorithm by tracking total incomplete entities
Diffstat (limited to 'engine/classes/ElggBatch.php')
-rw-r--r--engine/classes/ElggBatch.php18
1 files changed, 12 insertions, 6 deletions
diff --git a/engine/classes/ElggBatch.php b/engine/classes/ElggBatch.php
index ac79cf084..d810ea066 100644
--- a/engine/classes/ElggBatch.php
+++ b/engine/classes/ElggBatch.php
@@ -157,6 +157,13 @@ class ElggBatch
private $incompleteEntities = array();
/**
+ * Total number of incomplete entities fetched
+ *
+ * @var int
+ */
+ private $totalIncompletes = 0;
+
+ /**
* Batches operations on any elgg_get_*() or compatible function that supports
* an options array.
*
@@ -242,12 +249,9 @@ class ElggBatch
/**
* Fetches the next chunk of results
*
- * @param int $num_incompletes_last_fetch When called recursively, this is the number of
- * incomplete entities returned in the last fetch.
- *
* @return bool
*/
- private function getNextResultsChunk($num_incompletes_last_fetch = 0) {
+ private function getNextResultsChunk() {
// always reset results.
$this->results = array();
@@ -281,7 +285,7 @@ class ElggBatch
if ($this->incrementOffset) {
$offset = $this->offset + $this->retrievedResults;
} else {
- $offset = $this->offset + $num_incompletes_last_fetch;
+ $offset = $this->offset + $this->totalIncompletes;
}
$current_options = array(
@@ -298,6 +302,8 @@ class ElggBatch
$num_results = count($this->results);
$num_incomplete = count($this->incompleteEntities);
+ $this->totalIncompletes += $num_incomplete;
+
if ($this->incompleteEntities) {
// pad the front of the results with nulls representing the incompletes
array_splice($this->results, 0, 0, array_pad(array(), $num_incomplete, null));
@@ -318,7 +324,7 @@ class ElggBatch
if ($num_results == 0) {
// This fetch was *all* incompletes! We need to fetch until we can either
// offer at least one row to iterate over, or give up.
- return $this->getNextResultsChunk($num_incomplete);
+ return $this->getNextResultsChunk();
}
return true;
} else {