Browse Source

Updated db query code, fortunes url path in benchmark_config.json

Sanjoy Dey 10 years ago
parent
commit
c8e1d6db68

+ 23 - 15
frameworks/PHP/cygnite-php-framework/apps/controllers/BenchController.php

@@ -21,15 +21,23 @@ class BenchController extends AbstractBaseController
 
     public function dbAction($queries = 1)
     {
-        $worlds = array();
+        $worlds = $arr = array();
         $world = null;
+        $queries = intval($queries);
+
+        if ($queries < 1) {
+            $queries = 1;
+        } elseif ($queries > 500) {
+            $queries = 500;
+        }
 
         for ($i = 0; $i < $queries; ++$i) {
             $world = World::find(mt_rand(1, 10000));
-            $worlds[] = $world->getAttributes();
+            $arr['id'] = (int) $world->id;
+            $arr['randomNumber'] = (int) $world->randomnumber;
+            $worlds[] = $arr;
         }
 
-
         if ($queries == 1) {
             $worlds = $worlds[0];
         }
@@ -40,9 +48,9 @@ class BenchController extends AbstractBaseController
 
     public function fortunesAction()
     {
-        $allFortunes = array();
-        $allFortunes = Fortune::all();
-        $fortunes = $allFortunes->asArray();
+        $fortuneCollection = array();
+        $fortuneCollection = Fortune::all();
+        $fortunes = $fortuneCollection->asArray();
 
         $runtimeFortune = new Fortune();
         $runtimeFortune->id = 0;
@@ -52,18 +60,18 @@ class BenchController extends AbstractBaseController
 
         usort($fortunes, function($left, $right) {
 
-                if ($left->message === $right->message) {
-                    return 0;
-                } else if ($left->message > $right->message) {
-                    return 1;
-                } else {
-                    return -1;
-                }
+            if ($left->message === $right->message) {
+                return 0;
+            } else if ($left->message > $right->message) {
+                return 1;
+            } else {
+                return -1;
+            }
 
-            });
+        });
 
         $this->render('fortunes', array(
                 'fortunes' => $fortunes
-            ));
+        ));
     }
 }

+ 2 - 9
frameworks/PHP/cygnite-php-framework/apps/routes.php

@@ -27,17 +27,10 @@ $app->router->get('/plaintext', function ()
 });
 
 // Dynamic route: /fortunes
-$app->router->get('/fortunes', function ()
+/*$app->router->get('/fortunes', function ()
 {
     Router::call('Bench.fortunes', array());
-});
-
-/*
-$app->router->get('/db/{:digit}', function ($router, $id)
-{
-    Router::call('Bench.fortunes', array());
-});
-*/
+});*/
 
 /*
 GET       - resource/           user.getIndex

+ 2 - 1
frameworks/PHP/cygnite-php-framework/apps/views/bench/fortunes.view.php

@@ -10,7 +10,8 @@
     <?php foreach ($fortunes as $key => $fortune) { ?>
     <tr>
         <td><?php echo $fortune->id; ?></td>
-        <td><?php echo $fortune->message; ?></td>
+        <td><?php echo htmlentities($fortune->message, ENT_QUOTES, 'UTF-8', false); ?></td>
+
     </tr>
     <?php } ?>
 

+ 1 - 1
frameworks/PHP/cygnite-php-framework/benchmark_config.json

@@ -24,7 +24,7 @@
       "setup_file": "setup",
       "db_url": "/index.php/bench/db",
       "query_url": "/index.php/bench/db/",
-      "fortune_url": "/index.php/fortunes",
+      "fortune_url": "/index.php/bench/fortunes",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",