From 60b4c72f3928a594e9589e267efff2dd4b045847 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 28 Sep 2015 16:04:37 +0200 Subject: [PATCH] corrected bugs of optimization --- controllers/prototype/dbrequests.js | 18 ++++++++++++------ load.js => utils/load/load.js | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) rename load.js => utils/load/load.js (98%) diff --git a/controllers/prototype/dbrequests.js b/controllers/prototype/dbrequests.js index 3bb0dc8..50acdd1 100644 --- a/controllers/prototype/dbrequests.js +++ b/controllers/prototype/dbrequests.js @@ -499,7 +499,7 @@ DBReq.UserCreator = function(workerId, age, male, rating, lastTime, finishAction */ DBReq.UserCreator.prototype.execute = function() { var self = this; - this.client.query("BEGIN; LOCK Users;", [], function() { + this.client.query("BEGIN; LOCK Users IN SHARE ROW EXCLUSIVE MODE;", [], function() { self.client.query( "INSERT INTO users(worker_id, age, male, rating, lasttime) VALUES($1, $2, $3, $4, $5);", [ @@ -569,7 +569,7 @@ DBReq.ExpCreator = function(userId, experiments, finishAction) { self.startTime = Date.now(); // Start transaction and lock table - self.client.query("BEGIN; LOCK CoinCombination; LOCK Experiment;", [], function() { + self.client.query("BEGIN; LOCK CoinCombination IN SHARE ROW EXCLUSIVE MODE; LOCK Experiment IN SHARE ROW EXCLUSIVE MODE;", [], function() { self.execute(); }); }); @@ -579,9 +579,8 @@ function predicate(line) { return function(elt, idx, arr) { - console.log(elt.recommendationStyle, line.recommendationStyle); return ( - elt.recommendationStyle.trim() === line.recommendationStyle.trim() || + (elt.recommendationStyle !== null && (elt.recommendationStyle.trim() === line.recommendationStyle.trim())) || line.id === elt.coinCombinationId ); @@ -652,8 +651,6 @@ DBReq.ExpCreator.prototype.execute = function() { // Look for an experiment impossible var elt = self.experiments.find(predicate(line)); - // console.log(elt); - // Line is a valid experiment if (elt === undefined) { @@ -995,6 +992,15 @@ DBReq.LastExpGetter.prototype.execute = function() { 'LIMIT 1;', [self.userId], function (err, result) { + if (err !== null) { + Log.dberror(err + ' in LastExpGetter (DBReq)'); + } + if (result.rows.length === 0) { + setTimeout(function() { + self.execute(); + }, 1000); + return; + } self.finalResult.sceneId = result.rows[0].sceneId; self.finalResult.recommendationStyle = result.rows[0].recommendationStyle; self.finalResult.coins = [ diff --git a/load.js b/utils/load/load.js similarity index 98% rename from load.js rename to utils/load/load.js index 8c397d2..20ed514 100644 --- a/load.js +++ b/utils/load/load.js @@ -16,7 +16,7 @@ var casper = require('casper').create({ waitTimeout: 100000 }); -var limit = 1; +var limit = 100; casper.start('http://localhost:4000/');