Skip to content

Commit

Permalink
Patch bug in generatePool that fails to exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
martindale committed Feb 19, 2015
1 parent cdef7e7 commit 65a4622
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions models/Room.js
Expand Up @@ -135,6 +135,9 @@ RoomSchema.methods.generatePool = function( gain , failpoint , cb ) {
var failpoint = MAXIMUM_PLAY_AGE;
}

if (!gain) var gain = 0;
if (!failpoint) var failpoint = MAXIMUM_PLAY_AGE;

var query = {};

// must be queued by a real person
Expand All @@ -159,6 +162,7 @@ RoomSchema.methods.generatePool = function( gain , failpoint , cb ) {
}

Play.find( query ).limit( 4096 ).sort('timestamp').exec(function(err, plays) {
if (gain > failpoint) return cb('init');
if (err || !plays) return room.generatePool( gain + 7 , failpoint , cb );

Play.find({
Expand Down Expand Up @@ -192,6 +196,12 @@ RoomSchema.methods.selectTrack = function( cb ) {
var room = this;

room.generatePool(function(err, plays) {
if (err || !plays) {
return room.soundtrack.trackFromSource('youtube', 'wZThMWK9GxA', function(err, track) {
Artist.populate( track , '_artist' , cb );
});
}

var randomSelection = plays[ _.random(0, plays.length - 1 ) ];
Track.findOne({ _id: randomSelection._track }).populate('_artist').exec( cb );
});
Expand Down

0 comments on commit 65a4622

Please sign in to comment.