From f0a444bab7e2e80e61382e39c05b01cf8b71cd8a Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 28 Sep 2015 11:07:39 +0200 Subject: [PATCH] Attempt to optimize a request, and log time of creation of experiment --- controllers/prototype/dbrequests.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/controllers/prototype/dbrequests.js b/controllers/prototype/dbrequests.js index 53b1f17..e83bb4a 100644 --- a/controllers/prototype/dbrequests.js +++ b/controllers/prototype/dbrequests.js @@ -565,6 +565,8 @@ DBReq.ExpCreator = function(userId, finishAction) { self.client = client; self.release = release; + self.startTime = Date.now(); + // Start transaction and lock table self.client.query("BEGIN; LOCK CoinCombination; LOCK Experiment;", [], function() { self.execute(); @@ -664,8 +666,9 @@ DBReq.ExpCreator.prototype.execute = function() { "SELECT RecommendationStyle.name, Scene.id AS \"sceneId\"\n" + "FROM RecommendationStyle, Scene\n" + "WHERE\n" + + " Scene.name != 'peachcastle' AND \n" + " RecommendationStyle.name NOT IN(\n" + - " SELECT Experiment.recommendation_style AS name\n" + + " SELECT DISTINCT Experiment.recommendation_style AS name\n" + " FROM Experiment\n" + " WHERE Experiment.user_id = $1\n" + " AND Experiment.recommendation_style != ''\n" + @@ -676,8 +679,7 @@ DBReq.ExpCreator.prototype.execute = function() { " WHERE\n" + " Experiment.coin_combination_id = CoinCombination.id AND\n" + " user_id = $1\n" + - " ) AND\n" + - " Scene.name != 'peachcastle'\n" + + " ) \n" + "\n" + "ORDER BY RANDOM()\n" + "LIMIT 1;", @@ -766,6 +768,8 @@ DBReq.ExpCreator.prototype.finish = function() { // Commit, and then release this.client.query("COMMIT;", function() { + Log.debug('Exp creation took ' + (Date.now() - self.startTime) + ' ms'); + self.release(); self.client = null; self.release = null;