corrected bugs of optimization
This commit is contained in:
		
							parent
							
								
									8025de6b3b
								
							
						
					
					
						commit
						60b4c72f39
					
				
							
								
								
									
										18
									
								
								controllers/prototype/dbrequests.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								controllers/prototype/dbrequests.js
									
									
									
									
										vendored
									
									
								
							| @ -499,7 +499,7 @@ DBReq.UserCreator = function(workerId, age, male, rating, lastTime, finishAction | |||||||
|  */ |  */ | ||||||
| DBReq.UserCreator.prototype.execute = function() { | DBReq.UserCreator.prototype.execute = function() { | ||||||
|     var self = this; |     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( |         self.client.query( | ||||||
|             "INSERT INTO users(worker_id, age, male, rating, lasttime)  VALUES($1, $2, $3, $4, $5);", |             "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(); |         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 IN SHARE ROW EXCLUSIVE MODE; LOCK Experiment IN SHARE ROW EXCLUSIVE MODE;", [], function() { | ||||||
|             self.execute(); |             self.execute(); | ||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
| @ -579,9 +579,8 @@ function predicate(line) { | |||||||
| 
 | 
 | ||||||
|     return function(elt, idx, arr) { |     return function(elt, idx, arr) { | ||||||
| 
 | 
 | ||||||
|         console.log(elt.recommendationStyle, line.recommendationStyle); |  | ||||||
|         return ( |         return ( | ||||||
|             elt.recommendationStyle.trim() === line.recommendationStyle.trim() || |             (elt.recommendationStyle !== null && (elt.recommendationStyle.trim() === line.recommendationStyle.trim())) || | ||||||
|             line.id === elt.coinCombinationId |             line.id === elt.coinCombinationId | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
| @ -652,8 +651,6 @@ DBReq.ExpCreator.prototype.execute = function() { | |||||||
|                 // Look for an experiment impossible
 |                 // Look for an experiment impossible
 | ||||||
|                 var elt = self.experiments.find(predicate(line)); |                 var elt = self.experiments.find(predicate(line)); | ||||||
| 
 | 
 | ||||||
|                 // console.log(elt);
 |  | ||||||
| 
 |  | ||||||
|                 // Line is a valid experiment
 |                 // Line is a valid experiment
 | ||||||
|                 if (elt === undefined) { |                 if (elt === undefined) { | ||||||
| 
 | 
 | ||||||
| @ -995,6 +992,15 @@ DBReq.LastExpGetter.prototype.execute = function() { | |||||||
|         'LIMIT 1;', |         'LIMIT 1;', | ||||||
|         [self.userId], |         [self.userId], | ||||||
|         function (err, result) { |         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.sceneId = result.rows[0].sceneId; | ||||||
|             self.finalResult.recommendationStyle = result.rows[0].recommendationStyle; |             self.finalResult.recommendationStyle = result.rows[0].recommendationStyle; | ||||||
|             self.finalResult.coins = [ |             self.finalResult.coins = [ | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ var casper = require('casper').create({ | |||||||
|     waitTimeout: 100000 |     waitTimeout: 100000 | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| var limit = 1; | var limit = 100; | ||||||
| 
 | 
 | ||||||
| casper.start('http://localhost:4000/'); | casper.start('http://localhost:4000/'); | ||||||
| 
 | 
 | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user