Skip to content

Commit 9990f64

Browse files
mjanserruflin
authored andcommitted
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.
1 parent 838160b commit 9990f64

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ All notable changes to this project will be documented in this file based on the
3737
### Improvements
3838
* Added `native_function_invocation` CS rule [#1606](https://github.com/ruflin/Elastica/pull/1606)
3939
* Elasticsearch test version changed from 6.5.2 to 6.6.1 [#1620](https://github.com/ruflin/Elastica/pull/1620)
40+
* Clear scroll context also when empty page was received [#1660](https://github.com/ruflin/Elastica/pull/1660)
4041

4142
### Deprecated
4243

lib/Elastica/Scroll.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function next()
8585
} else {
8686
// If there are no pages left, we do not need to query ES.
8787
$this->clear();
88+
$this->_currentResultSet = null;
8889
}
8990
}
9091

@@ -147,7 +148,6 @@ public function clear()
147148

148149
// Reset scroll ID so valid() returns false.
149150
$this->_nextScrollId = null;
150-
$this->_currentResultSet = null;
151151
}
152152
}
153153

@@ -164,7 +164,13 @@ protected function _setScrollId(ResultSet $resultSet)
164164

165165
$this->_currentResultSet = $resultSet;
166166
++$this->currentPage;
167-
$this->_nextScrollId = $resultSet->getResponse()->isOk() && $resultSet->count() > 0 ? $resultSet->getResponse()->getScrollId() : null;
167+
$this->_nextScrollId = null;
168+
if ($resultSet->getResponse()->isOk()) {
169+
$this->_nextScrollId = $resultSet->getResponse()->getScrollId();
170+
if (0 === $resultSet->count()) {
171+
$this->clear();
172+
}
173+
}
168174
}
169175

170176
/**

test/Elastica/ScrollTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public function testEmptyScroll()
9595

9696
$this->assertEquals(0, $scroll->current()->count());
9797
$this->assertFalse($scroll->valid());
98+
99+
$this->_assertOpenSearchContexts($search->getClient(), 0);
98100
}
99101

100102
/**

0 commit comments

Comments
 (0)