Class yii\mongodb\debug\ExplainAction
Inheritance | yii\mongodb\debug\ExplainAction » yii\base\Action |
---|---|
Available since extension's version | 2.0.5 |
Source Code | https://github.com/yiisoft/yii2-mongodb/blob/master/src/debug/ExplainAction.php |
ExplainAction provides EXPLAIN information for MongoDB queries
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$panel | yii\mongodb\debug\MongoDbPanel | Related debug toolbar panel | yii\mongodb\debug\ExplainAction |
Public Methods
Method | Description | Defined By |
---|---|---|
run() | Runs the explain action | yii\mongodb\debug\ExplainAction |
Protected Methods
Method | Description | Defined By |
---|---|---|
explainQuery() | Runs explain command over the query | yii\mongodb\debug\ExplainAction |
Property Details
Related debug toolbar panel
Method Details
Runs explain command over the query
protected array|false explainQuery ( $queryString ) | ||
$queryString | string |
Query log string. |
return | array|false |
Explain results, |
---|
protected function explainQuery($queryString)
{
/* @var $connection \yii\mongodb\Connection */
$connection = $this->panel->getDb();
$queryInfo = Json::decode($queryString);
if (!isset($queryInfo['ns'])) {
return false;
}
list($databaseName, $collectionName) = explode('.', $queryInfo['ns'], 2);
unset($queryInfo['ns']);
if (!empty($queryInfo['filer'])) {
$queryInfo['filer'] = $this->prepareQueryFiler($queryInfo['filer']);
}
return $connection->createCommand($databaseName)->explain($collectionName, $queryInfo);
}
Runs the explain action
public string run ( $seq, $tag ) | ||
$seq | integer | |
$tag | string | |
return | string |
Explain result content |
---|---|---|
throws | \yii\web\HttpException |
if requested log not found |
public function run($seq, $tag)
{
$this->controller->loadData($tag);
$timings = $this->panel->calculateTimings();
if (!isset($timings[$seq])) {
throw new HttpException(404, 'Log message not found.');
}
$query = $timings[$seq]['info'];
if (strpos($query, 'find({') !== 0) {
return '';
}
$query = substr($query, strlen('find('), -1);
$result = $this->explainQuery($query);
if (!$result) {
return '';
}
return Json::encode($result, JSON_PRETTY_PRINT);
}