Differential D12438 Diff 29881 src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php
Show All 19 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$class = nonempty($request->getURIData('class'), $request->getStr('class')); | $class = nonempty($request->getURIData('class'), $request->getStr('class')); | ||||
$sources = id(new PhutilSymbolLoader()) | $sources = id(new PhutilSymbolLoader()) | ||||
->setAncestorClass('PhabricatorTypeaheadDatasource') | ->setAncestorClass('PhabricatorTypeaheadDatasource') | ||||
->loadObjects(); | ->loadObjects(); | ||||
if (isset($sources[$class])) { | if (isset($sources[$class])) { | ||||
$source = $sources[$class]; | $source = $sources[$class]; | ||||
$source->setParameters($request->getRequestData()); | $source->setParameters($request->getRequestData()); | ||||
$source->setViewer($viewer); | |||||
// NOTE: Wrapping the source in a Composite datasource ensures we perform | // NOTE: Wrapping the source in a Composite datasource ensures we perform | ||||
// application visibility checks for the viewer, so we do not need to do | // application visibility checks for the viewer, so we do not need to do | ||||
// those separately. | // those separately. | ||||
$composite = new PhabricatorTypeaheadRuntimeCompositeDatasource(); | $composite = new PhabricatorTypeaheadRuntimeCompositeDatasource(); | ||||
$composite->addDatasource($source); | $composite->addDatasource($source); | ||||
$composite | $composite | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setQuery($query) | ->setQuery($query) | ||||
->setRawQuery($raw_query); | ->setRawQuery($raw_query); | ||||
$hard_limit = 1000; | $hard_limit = 1000; | ||||
if ($is_browse) { | if ($is_browse) { | ||||
if (!$composite->isBrowsable()) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$limit = 10; | $limit = 10; | ||||
$offset = $request->getInt('offset'); | $offset = $request->getInt('offset'); | ||||
if (($offset + $limit) >= $hard_limit) { | if (($offset + $limit) >= $hard_limit) { | ||||
// Offset-based paging is intrinsically slow; hard-cap how far we're | // Offset-based paging is intrinsically slow; hard-cap how far we're | ||||
// willing to go with it. | // willing to go with it. | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |