This commit is contained in:
Charles Chong 2014-04-02 21:05:32 -07:00
Родитель 485f21e9b3
Коммит c4c256bc93
2 изменённых файлов: 20 добавлений и 16 удалений

Просмотреть файл

@ -24,7 +24,7 @@ function newGame(client, data, developerID, callback) {
callback(null, data);
}
});
client.zadd('gamesByStatus:pending', Date.now(), data.id);
client.zadd('gamesByStatus:' + data.status, Date.now(), data.id);
}
exports.newGame = newGame;
@ -48,7 +48,7 @@ function updateGame(client, gameSlug, updatedGame, callback) {
client.hset('gamesBySlug', updatedGame.slug, game.id);
client.hdel('gamesBySlug', game.slug);
}
if (game.status != updatedGame.status) {
if (game.status !== updatedGame.status) {
client.zrem('gamesByStatus:' + game.status, game.id);
client.zadd('gamesByStatus:' + updatedGame.status, Date.now(), game.id);
}

Просмотреть файл

@ -119,34 +119,38 @@ module.exports = function(server) {
}
// Pick the first 'count' games
var gamesUpToCount = _.first(filteredGames, count);
if (developerFilter) {
// Add queue position if using the developer filter
function queuePromise(game) {
return new Promise(function(resolve, reject){
if (game.status === "pending"){
client.zrank("gamesByStatus:pending", game.id,
db.plsNoError(res, done, function(rank) {
game.queuePosition = rank + 1;
done();
resolve(game);
}));
return new Promise(function(resolve, reject) {
if (game.status === 'pending') {
client.zrank('gamesByStatus:pending', game.id,
function(err, rank) {
if (err) {
reject(err);
} else {
game.queuePosition = rank + 1;
resolve(game);
}
});
} else {
resolve(game);
}
});
}
Promise.all(gamesUpToCount.map(queuePromise)).then(function(gamesWithQueuePosition){
gamesWithQueuePosition.map(gamelib.publicGameObj);
res.json(gamesWithQueuePosition);
Promise.all(gamesUpToCount.map(queuePromise)).then(function(games) {
var publicGames = games.map(gamelib.publicGameObj);
res.json(publicGames);
done();
}, function(err){
}, function(err) {
res.json(500, {error: err || 'db_error'});
done();
});
} else {
gamesUpToCount.map(gamelib.publicGameObj);
res.json(gamesUpToCount);
var publicGames = gamesUpToCount.map(gamelib.publicGameObj);
res.json(publicGames);
done();
}
}