1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 05:20:56 +01:00

Allow ApplicationSearch to be offset-paged

Summary: Ref T4365. It's not practical to cursor-page all engines; allow main search engines to be offset-paged. Basically, this comes down to setting a flag and then doing a couple of tiny things differently.

Test Plan: Used this two diffs from now.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4365

Differential Revision: https://secure.phabricator.com/D8121
This commit is contained in:
epriestley 2014-02-03 12:52:19 -08:00
parent e7d671c8d3
commit a82f573102
4 changed files with 38 additions and 13 deletions

View file

@ -7,6 +7,16 @@ final class PhabricatorApplicationSearchController
private $navigation; private $navigation;
private $queryKey; private $queryKey;
private $preface; private $preface;
private $useOffsetPaging;
public function setUseOffsetPaging($use_offset_paging) {
$this->useOffsetPaging = $use_offset_paging;
return $this;
}
public function getUseOffsetPaging() {
return $this->useOffsetPaging;
}
public function setPreface($preface) { public function setPreface($preface) {
$this->preface = $preface; $this->preface = $preface;
@ -213,7 +223,12 @@ final class PhabricatorApplicationSearchController
$query = $engine->buildQueryFromSavedQuery($saved_query); $query = $engine->buildQueryFromSavedQuery($saved_query);
$use_offset_paging = $this->getUseOffsetPaging();
if ($use_offset_paging) {
$pager = new AphrontPagerView();
} else {
$pager = new AphrontCursorPagerView(); $pager = new AphrontCursorPagerView();
}
$pager->readFromRequest($request); $pager->readFromRequest($request);
$page_size = $engine->getPageSize($saved_query); $page_size = $engine->getPageSize($saved_query);
if (is_finite($page_size)) { if (is_finite($page_size)) {
@ -225,8 +240,14 @@ final class PhabricatorApplicationSearchController
// with INF seems to vary across PHP versions, systems, and runtimes. // with INF seems to vary across PHP versions, systems, and runtimes.
$pager->setPageSize(0xFFFF); $pager->setPageSize(0xFFFF);
} }
$objects = $query->setViewer($request->getUser())
->executeWithCursorPager($pager); $query->setViewer($request->getUser());
if ($use_offset_paging) {
$objects = $query->executeWithOffsetPager($pager);
} else {
$objects = $query->executeWithCursorPager($pager);
}
$list = $parent->renderResultsList($objects, $saved_query); $list = $parent->renderResultsList($objects, $saved_query);

View file

@ -349,7 +349,7 @@ abstract class PhabricatorApplicationSearchEngine {
* This provides flexibility when constructing URIs, especially from external * This provides flexibility when constructing URIs, especially from external
* sources. * sources.
* *
* @param AphrontRequest Request to read PHIDs from. * @param AphrontRequest Request to read strings from.
* @param string Key to read in the request. * @param string Key to read in the request.
* @return list<string> List of values. * @return list<string> List of values.
*/ */

View file

@ -11,16 +11,9 @@ final class PhabricatorSearchIndexer {
} }
public function indexDocumentByPHID($phid) { public function indexDocumentByPHID($phid) {
$doc_indexer_symbols = id(new PhutilSymbolLoader()) $indexers = id(new PhutilSymbolLoader())
->setAncestorClass('PhabricatorSearchDocumentIndexer') ->setAncestorClass('PhabricatorSearchDocumentIndexer')
->setConcreteOnly(true) ->loadObjects();
->setType('class')
->selectAndLoadSymbols();
$indexers = array();
foreach ($doc_indexer_symbols as $symbol) {
$indexers[] = newv($symbol['name'], array());
}
foreach ($indexers as $indexer) { foreach ($indexers as $indexer) {
if ($indexer->shouldIndexDocumentByPHID($phid)) { if ($indexer->shouldIndexDocumentByPHID($phid)) {

View file

@ -47,6 +47,17 @@ final class AphrontPagerView extends AphrontView {
return $this; return $this;
} }
final public function readFromRequest(AphrontRequest $request) {
$this->uri = $request->getRequestURI();
$this->pagingParameter = 'offset';
$this->offset = $request->getInt($this->pagingParameter);
return $this;
}
final public function willShowPagingControls() {
return $this->hasMorePages;
}
final public function setSurroundingPages($pages) { final public function setSurroundingPages($pages) {
$this->surroundingPages = max(0, $pages); $this->surroundingPages = max(0, $pages);
return $this; return $this;