Attempt to optimize a request, and log time of creation of experiment

This commit is contained in:
Thomas FORGIONE 2015-09-28 11:07:39 +02:00
parent 96cb58b6f6
commit f0a444bab7
1 changed files with 7 additions and 3 deletions

View File

@ -565,6 +565,8 @@ DBReq.ExpCreator = function(userId, finishAction) {
self.client = client; self.client = client;
self.release = release; self.release = release;
self.startTime = Date.now();
// Start transaction and lock table // Start transaction and lock table
self.client.query("BEGIN; LOCK CoinCombination; LOCK Experiment;", [], function() { self.client.query("BEGIN; LOCK CoinCombination; LOCK Experiment;", [], function() {
self.execute(); self.execute();
@ -664,8 +666,9 @@ DBReq.ExpCreator.prototype.execute = function() {
"SELECT RecommendationStyle.name, Scene.id AS \"sceneId\"\n" + "SELECT RecommendationStyle.name, Scene.id AS \"sceneId\"\n" +
"FROM RecommendationStyle, Scene\n" + "FROM RecommendationStyle, Scene\n" +
"WHERE\n" + "WHERE\n" +
" Scene.name != 'peachcastle' AND \n" +
" RecommendationStyle.name NOT IN(\n" + " RecommendationStyle.name NOT IN(\n" +
" SELECT Experiment.recommendation_style AS name\n" + " SELECT DISTINCT Experiment.recommendation_style AS name\n" +
" FROM Experiment\n" + " FROM Experiment\n" +
" WHERE Experiment.user_id = $1\n" + " WHERE Experiment.user_id = $1\n" +
" AND Experiment.recommendation_style != ''\n" + " AND Experiment.recommendation_style != ''\n" +
@ -676,8 +679,7 @@ DBReq.ExpCreator.prototype.execute = function() {
" WHERE\n" + " WHERE\n" +
" Experiment.coin_combination_id = CoinCombination.id AND\n" + " Experiment.coin_combination_id = CoinCombination.id AND\n" +
" user_id = $1\n" + " user_id = $1\n" +
" ) AND\n" + " ) \n" +
" Scene.name != 'peachcastle'\n" +
"\n" + "\n" +
"ORDER BY RANDOM()\n" + "ORDER BY RANDOM()\n" +
"LIMIT 1;", "LIMIT 1;",
@ -766,6 +768,8 @@ DBReq.ExpCreator.prototype.finish = function() {
// Commit, and then release // Commit, and then release
this.client.query("COMMIT;", function() { this.client.query("COMMIT;", function() {
Log.debug('Exp creation took ' + (Date.now() - self.startTime) + ' ms');
self.release(); self.release();
self.client = null; self.client = null;
self.release = null; self.release = null;