From c3b9d7842743d09405ea01ad0d1adc0deb4358c7 Mon Sep 17 00:00:00 2001 From: bethrezen Date: Tue, 30 Sep 2014 17:55:09 +0400 Subject: [PATCH] Faster count query using getFullCount except getCount --- Query.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Query.php b/Query.php index 2d035c9..4d5c18d 100644 --- a/Query.php +++ b/Query.php @@ -616,8 +616,13 @@ class Query extends Component implements QueryInterface public function count($q = '*', $db = null) { + $this->select = '1'; + $this->limit(1); + $this->offset(0); $statement = $this->createCommand($db); - $statement->setCount(true); + $statement->setFullCount(true); + $statement->setBatchSize(1); + $token = $this->getRawAql($statement); Yii::info($token, 'devgroup\arangodb\Query::query'); try { @@ -628,7 +633,7 @@ class Query extends Component implements QueryInterface Yii::endProfile($token, 'devgroup\arangodb\Query::query'); throw new \Exception($ex->getMessage(), (int) $ex->getCode(), $ex); } - return $cursor->getCount(); + return $cursor->getFullCount(); } public function exists($db = null)