diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f6ca7a0010..75f0db1381 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -9148,7 +9148,7 @@ phutil_register_library_map(array( 'PhabricatorSearchDocument' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentFieldType' => 'Phobject', - 'PhabricatorSearchDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorSearchDocumentQuery' => 'PhabricatorPolicyAwareQuery', 'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentTypeDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorSearchEditController' => 'PhabricatorSearchBaseController', diff --git a/src/applications/search/query/PhabricatorSearchDocumentQuery.php b/src/applications/search/query/PhabricatorSearchDocumentQuery.php index d4700904c9..fb6e23c6d4 100644 --- a/src/applications/search/query/PhabricatorSearchDocumentQuery.php +++ b/src/applications/search/query/PhabricatorSearchDocumentQuery.php @@ -1,10 +1,11 @@ savedQuery = $query; @@ -20,11 +21,27 @@ final class PhabricatorSearchDocumentQuery if ($this->objectCapabilities) { return $this->objectCapabilities; } + return $this->getRequiredCapabilities(); } + protected function willExecute() { + $this->unfilteredOffset = 0; + } + protected function loadPage() { - $phids = $this->loadDocumentPHIDsWithoutPolicyChecks(); + // NOTE: The offset and limit information in the inherited properties of + // this object represent a policy-filtered offset and limit, but the + // underlying query engine needs an unfiltered offset and limit. We keep + // track of an unfiltered result offset internally. + + $query = id(clone($this->savedQuery)) + ->setParameter('offset', $this->unfilteredOffset) + ->setParameter('limit', $this->getRawResultLimit()); + + $phids = PhabricatorSearchService::executeSearch($query); + + $this->unfilteredOffset += count($phids); $handles = id(new PhabricatorHandleQuery()) ->setViewer($this->getViewer()) @@ -69,25 +86,13 @@ final class PhabricatorSearchDocumentQuery return $handles; } - public function loadDocumentPHIDsWithoutPolicyChecks() { - $query = id(clone($this->savedQuery)) - ->setParameter('offset', $this->getOffset()) - ->setParameter('limit', $this->getRawResultLimit()); - return PhabricatorSearchService::executeSearch($query); - } - public function getQueryApplicationClass() { return 'PhabricatorSearchApplication'; } - protected function getResultCursor($result) { - throw new Exception( - pht( - 'This query does not support cursor paging; it must be offset paged.')); - } - protected function nextPage(array $page) { - $this->setOffset($this->getOffset() + count($page)); + // We already updated the internal offset in `loadPage()` after loading + // results, so we do not need to make any additional state updates here. return $this; } diff --git a/src/view/phui/PHUIPagerView.php b/src/view/phui/PHUIPagerView.php index 232d4ab747..b78efcda96 100644 --- a/src/view/phui/PHUIPagerView.php +++ b/src/view/phui/PHUIPagerView.php @@ -55,7 +55,7 @@ final class PHUIPagerView extends AphrontView { } public function willShowPagingControls() { - return $this->hasMorePages; + return $this->hasMorePages || $this->getOffset(); } public function getHasMorePages() {