MDL-60720 core_search: Indexing halts on failed get_document

The recordsets used for search indexing sometimes return results
which are invalid (e.g. cannot be found in database). When this
happens, the result in the iterator for the recordset will be
false. Due to a bug, the iterator used to stop when it encountered
a false value, which prevented indexing from getting past the
problematic record.

In addition, the iterator that skips future data resulted in the
current() function of its parent indicator being called twice per
entry, which meant that search indexing called get_document()
twice as many times.
This commit is contained in:
sam marshall
2017-11-07 16:36:37 +00:00
parent 159b4e5d8c
commit 4b0facc984
2 changed files with 267 additions and 5 deletions
@@ -46,6 +46,12 @@ class skip_future_documents_iterator implements \Iterator {
/** @var int Cutoff time; anything later than this will cause the iterator to stop */
protected $cutoff;
/** @var mixed Current value of iterator */
protected $currentdoc;
/** @var bool True if current value is available */
protected $gotcurrent;
/**
* Constructor.
*
@@ -62,11 +68,16 @@ class skip_future_documents_iterator implements \Iterator {
}
public function current() {
return $this->parent->current();
if (!$this->gotcurrent) {
$this->currentdoc = $this->parent->current();
$this->gotcurrent = true;
}
return $this->currentdoc;
}
public function next() {
$this->parent->next();
$this->gotcurrent = false;
}
public function key() {
@@ -79,16 +90,17 @@ class skip_future_documents_iterator implements \Iterator {
return false;
}
if ($doc = $this->parent->current()) {
if ($doc = $this->current()) {
// This document is valid if the modification date is before the cutoff.
return $doc->get('modified') <= $this->cutoff;
} else {
// If the document is false/null, allow iterator to continue.
return true;
}
return false;
}
public function rewind() {
$this->parent->rewind();
$this->gotcurrent = false;
}
}