Differential D15790 Diff 38037 src/applications/diffusion/conduit/DiffusionQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionQueryConduitAPIMethod.php
Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | final protected function execute(ConduitAPIRequest $request) { | ||||
// Figure out whether we're going to handle this request on this device, | // Figure out whether we're going to handle this request on this device, | ||||
// or proxy it to another node in the cluster. | // or proxy it to another node in the cluster. | ||||
// If this is a cluster request and we need to proxy, we'll explode here | // If this is a cluster request and we need to proxy, we'll explode here | ||||
// to prevent infinite recursion. | // to prevent infinite recursion. | ||||
$is_cluster_request = $request->getIsClusterRequest(); | $is_cluster_request = $request->getIsClusterRequest(); | ||||
$viewer = $request->getUser(); | |||||
$repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
$client = $repository->newConduitClient( | $client = $repository->newConduitClient( | ||||
$request->getUser(), | $viewer, | ||||
$is_cluster_request); | $is_cluster_request); | ||||
if ($client) { | if ($client) { | ||||
// We're proxying, so just make an intracluster call. | // We're proxying, so just make an intracluster call. | ||||
return $client->callMethodSynchronous( | return $client->callMethodSynchronous( | ||||
$this->getAPIMethodName(), | $this->getAPIMethodName(), | ||||
$request->getAllParameters()); | $request->getAllParameters()); | ||||
} else { | } else { | ||||
// We pass this flag on to prevent proxying of any other Conduit calls | // We pass this flag on to prevent proxying of any other Conduit calls | ||||
// which we need to make in order to respond to this one. Although we | // which we need to make in order to respond to this one. Although we | ||||
// could safely proxy them, we take a big performance hit in the common | // could safely proxy them, we take a big performance hit in the common | ||||
// case, and doing more proxying wouldn't exercise any additional code so | // case, and doing more proxying wouldn't exercise any additional code so | ||||
// we wouldn't gain a testability/predictability benefit. | // we wouldn't gain a testability/predictability benefit. | ||||
$drequest->setIsClusterRequest($is_cluster_request); | $drequest->setIsClusterRequest($is_cluster_request); | ||||
$this->setDiffusionRequest($drequest); | $this->setDiffusionRequest($drequest); | ||||
// TODO: Allow web UI queries opt out of this if they don't care about | // TODO: Allow web UI queries opt out of this if they don't care about | ||||
// fetching the most up-to-date data? Synchronization can be slow, and a | // fetching the most up-to-date data? Synchronization can be slow, and a | ||||
// lot of web reads are probably fine if they're a few seconds out of | // lot of web reads are probably fine if they're a few seconds out of | ||||
// date. | // date. | ||||
$repository->synchronizeWorkingCopyBeforeRead(); | id(new DiffusionRepositoryClusterEngine()) | ||||
->setViewer($viewer) | |||||
->setRepository($repository) | |||||
->synchronizeWorkingCopyBeforeRead(); | |||||
return $this->getResult($request); | return $this->getResult($request); | ||||
} | } | ||||
} | } | ||||
protected function getResult(ConduitAPIRequest $request) { | protected function getResult(ConduitAPIRequest $request) { | ||||
$repository = $this->getRepository($request); | $repository = $this->getRepository($request); | ||||
$result = null; | $result = null; | ||||
Show All 18 Lines |