Browse Source

Merge pull request #741 from kpacha/fix-php-phalcon-queries-test-validation

Fix the php-phalcon queries test validation
Mike Smith 11 years ago
parent
commit
d1c6759b89

+ 2 - 2
php-phalcon/README.md

@@ -41,8 +41,8 @@ MongoDB: http://localhost/mongodb/db
 
 ### Variable Query Test
     
-MySQL: http://localhost/db?queries=2
-MongoDB: http://localhost/mongodb/db?queries=2
+MySQL: http://localhost/queries?queries=2
+MongoDB: http://localhost/mongodb/queries?queries=2
 
 ### Update Test
     

+ 10 - 2
php-phalcon/app/config/routes.php

@@ -7,12 +7,16 @@ $router->add('/json', array(
     'action' => 'json',
 ));
 
-// Handles "/db" as well as "/db?queries={queries}"
 $router->add('/db', array(
     'controller' => 'bench',
     'action' => 'db',
 ));
 
+$router->add('/queries', array(
+    'controller' => 'bench',
+    'action' => 'queries',
+));
+
 $router->add('/fortunes', array(
     'controller' => 'bench',
     'action' => 'fortunes',
@@ -28,12 +32,16 @@ $router->add('/plaintext', array(
     'action' => 'plaintext',
 ));
 
-// Handles "/db" as well as "/db?queries={queries}"
 $router->add('/mongodb/db', array(
     'controller' => 'mongobench',
     'action' => 'db',
 ));
 
+$router->add('/mongodb/queries', array(
+    'controller' => 'mongobench',
+    'action' => 'queries',
+));
+
 $router->add('/mongodb/fortunes', array(
     'controller' => 'mongobench',
     'action' => 'fortunes',

+ 7 - 7
php-phalcon/app/controllers/BenchController.php

@@ -21,8 +21,13 @@ class BenchController extends \Phalcon\Mvc\Controller
 
     public function dbAction()
     {
+        return $this->sendContentAsJson($this->getRandomWorld());
+    }
 
-        $queries = $this->request->getQuery('queries', null, 1);
+    public function queriesAction()
+    {
+
+	$queries = min(500, max(1, $this->filter->sanitize($this->request->getQuery('queries', null, 1), "int")));
 
         $worlds = array();
 
@@ -30,12 +35,7 @@ class BenchController extends \Phalcon\Mvc\Controller
             $worlds[] = $this->getRandomWorld();
         }
 
-        if (count($worlds) == 1) {
-            return $this->sendContentAsJson($worlds[0]);
-        }
-        else {
-            return $this->sendContentAsJson($worlds);
-        }
+        return $this->sendContentAsJson($worlds);
     }
 
     public function fortunesAction()

+ 2 - 2
php-phalcon/benchmark_config

@@ -5,7 +5,7 @@
       "setup_file": "setup",
       "json_url": "/json",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/queries?queries=",
       "fortune_url": "/fortunes",
       "update_url": "/update?queries=",
       "port": 8080,
@@ -26,7 +26,7 @@
     "mongodb": {
       "setup_file": "setup",
       "db_url": "/mongodb/db",
-      "query_url": "/mongodb/db?queries=",
+      "query_url": "/mongodb/queries?queries=",
       "fortune_url": "/mongodb/fortunes",
       "port": 8080,
       "approach": "Realistic",