Browse Source

Merge branch '777'

James Yen 11 years ago
parent
commit
3a38b08fb1
1 changed files with 5 additions and 3 deletions
  1. 5 3
      express/app.js

+ 5 - 3
express/app.js

@@ -10,7 +10,7 @@ var cluster = require('cluster')
   , mongoose = require('mongoose')
   , async = require('async')
   , conn = mongoose.connect('mongodb://localhost/hello_world')
-  , connMap = { user: 'benchmarkdbuser', password: 'benchmarkdbpass', database: 'hello_world', host: 'localhost' };
+  , connMap = { user: 'benchmarkdbuser', password: 'benchmarkdbpass', database: 'hello_world', host: 'localhost', charset: 'utf8' };
 
 var Schema = mongoose.Schema
   , ObjectId = Schema.ObjectId;
@@ -89,10 +89,12 @@ if (cluster.isMaster) {
   app.get('/mysql-orm', function(req, res) {
     if (windows) return res.send(501, 'Not supported on windows');
     
-    var queries = req.query.queries || 1
+    var queries = isNaN(req.query.queries) ? 1 : parseInt(req.query.queries, 10)
       , worlds  = []
       , queryFunctions = [];
 
+    queries = Math.min(Math.max(queries, 1), 500);
+
     for (var i = 1; i <= queries; i++ ) {
       queryFunctions.push(function(callback) {
         World.findById(Math.floor(Math.random()*10000) + 1, function (err, world) {
@@ -103,7 +105,7 @@ if (cluster.isMaster) {
     }
 
     async.parallel(queryFunctions, function(err, results) {
-      if (queries == 1) {
+      if (!req.query.queries) {
         worlds = worlds[0];
       }
       res.send(worlds);