Skip to content
Permalink
Browse files

Clear scroll context also when empty page was received (#1660)

Scroll contexts should always be cleared when they're not used
anymore. Retrieving an empty page from a scroll means it's finished
and the context can be cleared.
  • Loading branch information
mjanser authored and ruflin committed Sep 5, 2019
1 parent 838160b commit 9990f6425f1de55079574f6e102be78916b20570
Showing with 11 additions and 2 deletions.
  1. +1 −0 CHANGELOG.md
  2. +8 −2 lib/Elastica/Scroll.php
  3. +2 −0 test/Elastica/ScrollTest.php
@@ -37,6 +37,7 @@ All notable changes to this project will be documented in this file based on the
### Improvements
* Added `native_function_invocation` CS rule [#1606](https://github.com/ruflin/Elastica/pull/1606)
* Elasticsearch test version changed from 6.5.2 to 6.6.1 [#1620](https://github.com/ruflin/Elastica/pull/1620)
* Clear scroll context also when empty page was received [#1660](https://github.com/ruflin/Elastica/pull/1660)

### Deprecated

@@ -85,6 +85,7 @@ public function next()
} else {
// If there are no pages left, we do not need to query ES.
$this->clear();
$this->_currentResultSet = null;
}
}
@@ -147,7 +148,6 @@ public function clear()
// Reset scroll ID so valid() returns false.
$this->_nextScrollId = null;
$this->_currentResultSet = null;
}
}
@@ -164,7 +164,13 @@ protected function _setScrollId(ResultSet $resultSet)
$this->_currentResultSet = $resultSet;
++$this->currentPage;
$this->_nextScrollId = $resultSet->getResponse()->isOk() && $resultSet->count() > 0 ? $resultSet->getResponse()->getScrollId() : null;
$this->_nextScrollId = null;
if ($resultSet->getResponse()->isOk()) {
$this->_nextScrollId = $resultSet->getResponse()->getScrollId();
if (0 === $resultSet->count()) {
$this->clear();
}
}
}
/**
@@ -95,6 +95,8 @@ public function testEmptyScroll()
$this->assertEquals(0, $scroll->current()->count());
$this->assertFalse($scroll->valid());
$this->_assertOpenSearchContexts($search->getClient(), 0);
}
/**

0 comments on commit 9990f64

Please sign in to comment.
You can’t perform that action at this time.