<commit_before>var _ = require('lodash');
var uuid = require('node-uuid');

var utils = require('./utils');


function newGame(client, data, developerID, callback) {
    data.id = uuid.v4();
    data.created = data.modified = new Date();
    data.status = 'pending';
    data.slug = utils.slugify(data.slug || data.name);

    client.hset('games', data.id, JSON.stringify(data));

    // TODO: enforce slug uniqueness #108
    client.hset('gamesBySlug', data.slug, data.id);
    client.hget('gameIDsByDeveloperID', developerID, function(err, resp) {
        if (err) {
            callback('db_error');
        } else {
            var respData = resp ? JSON.parse(resp) : [];
            respData.push(data.id);
            client.hset('gameIDsByDeveloperID', developerID, JSON.stringify(respData));
            callback(null, data);
        }
    });
    client.zadd('gamesByStatus:' + data.status, Date.now(), data.id);
}
exports.newGame = newGame;


function updateGame(client, gameSlug, updatedGame, callback) {
    getGameFromSlug(client, gameSlug, function(err, game) {
        if (err) {
            callback(err);
        } else if (!game) {
            callback('no_such_game');
        } else {
            // Ensure that we don't change the id of the game, and
            // update the modified timestamp
            updatedGame.id = game.id;
            updatedGame.modified = new Date();

            client.hset('games', game.id, JSON.stringify(updatedGame));

            // TODO: enforce slug uniqueness #108
            if (game.slug !== updatedGame.slug) {<commit_msg>Fixed race condition with gameIDsByDeveloperID ranking on game creation<commit_after>var _ = require('lodash');
var uuid = require('node-uuid');

var utils = require('./utils');


function newGame(client, data, developerID, callback) {
    data.id = uuid.v4();
    data.created = data.modified = new Date();
    data.status = 'pending';
    data.slug = utils.slugify(data.slug || data.name);

    client.hset('games', data.id, JSON.stringify(data));

    // TODO: enforce slug uniqueness #108
    client.hset('gamesBySlug', data.slug, data.id);
    client.hget('gameIDsByDeveloperID', developerID, function(err, resp) {
        if (err) {
            callback('db_error');
        } else {
            var respData = resp ? JSON.parse(resp) : [];
            respData.push(data.id);
            client.hset('gameIDsByDeveloperID', developerID, JSON.stringify(respData));
            callback(null, data);
        }
    });
    client.zadd('gamesByStatus:' + data.status, data.created.getTime(), data.id);
}
exports.newGame = newGame;


function updateGame(client, gameSlug, updatedGame, callback) {
    getGameFromSlug(client, gameSlug, function(err, game) {
        if (err) {
            callback(err);
        } else if (!game) {
            callback('no_such_game');
        } else {
            // Ensure that we don't change the id of the game, and
            // update the modified timestamp
            updatedGame.id = game.id;
            updatedGame.modified = new Date();

            client.hset('games', game.id, JSON.stringify(updatedGame));

            // TODO: enforce slug uniqueness #108
            if (game.slug !== updatedGame.slug) {
{'fraction_non_alphanumeric': 0.13955637707948243, 'fraction_numerical': 0.004313000616142945, 'mean_word_length': 2.4989224137931036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '558642', 'n_tokens_mistral': 982, 'n_tokens_neox': 953, 'n_words': 222}