<commit_before>var redisClient = require("./redis_client"),
    createGuid = require("./create_guid"),
    tables = require("./tables");

function MatchRequest(guid, data) {
  var self = this;

  self.scheduleForMatch = function() {
    var matchTypes = {
      singles: { maxNumOfPlayers: 2 },
      doubles: { maxNumOfPlayers: 4 }
    };

    var neededNumberOfPlayers = matchTypes[data.matchType].maxNumOfPlayers - data.numPlayers,
    newMatchKey = data.matchType + ":" + neededNumberOfPlayers,
    pendingMatchKey = data.matchType + ":" + data.numPlayers;

    function transactionallyScheduleMatch() {
      var tryNumber = 1;
      var repeatFunction = function(err) {
        if(err && (tryNumber++ < 3)) {
          transactionallScheduleMatch();
        }
      };

      redisClient.watch(pendingMatchKey);
      var max = function(a, b) { return a > b ? a : b },
      min = function(a, b) { return a < b ? a : b },
      pendingGuid = redisClient.get(pendingMatchKey),
      pendingOpponentNames = redisClient.hmget(pendingGuid, 'names'),
      expirationTime = min(max(data.requestTTL || 9*60, 1), 9*60) * 60;

      redisClient.get(pendingMatchKey, function(err, pendingGuid){
        redisClient.hmget(pendingGuid, 'names', function(err, pendingOpponentNames){
          if(pendingGuid) {
            var matchGuid = createGuid(),
            selectedTableName = tables.pickMatchTable();

            console.log("scheduled match with: " + pendingOpponentNames);

            redisClient.multi()
            .del(pendingMatchKey)
            .hset(pendingGuid, 'scheduledMatchGuid', matchGuid)
            .hset(guid, 'scheduledMatchGuid', matchGuid)
            .hset(pendingGuid, 'confirmed', 0)
            .hset(guid, 'confirmed', 0)
            .hmset(matchGuid, {team1: pendingGuid, team2: guid, tableName: selectedTableName})
            .expire(matchGuid, 80)
            .expire(pendingGuid, 80)
            .expire(guid, 80)
            .exec(repeatFunction);
          } else {
            redisClient.multi()
            .set(newMatchKey, guid)
            .expire(newMatchKey, expirationTime)<commit_msg>Decrease amount of time to confirm a match by about half based on user feedback<commit_after>var redisClient = require("./redis_client"),
    createGuid = require("./create_guid"),
    tables = require("./tables");

function MatchRequest(guid, data) {
  var self = this;

  self.scheduleForMatch = function() {
    var matchTypes = {
      singles: { maxNumOfPlayers: 2 },
      doubles: { maxNumOfPlayers: 4 }
    };

    var neededNumberOfPlayers = matchTypes[data.matchType].maxNumOfPlayers - data.numPlayers,
    newMatchKey = data.matchType + ":" + neededNumberOfPlayers,
    pendingMatchKey = data.matchType + ":" + data.numPlayers;

    function transactionallyScheduleMatch() {
      var tryNumber = 1;
      var repeatFunction = function(err) {
        if(err && (tryNumber++ < 3)) {
          transactionallScheduleMatch();
        }
      };

      redisClient.watch(pendingMatchKey);
      var max = function(a, b) { return a > b ? a : b },
      min = function(a, b) { return a < b ? a : b },
      pendingGuid = redisClient.get(pendingMatchKey),
      pendingOpponentNames = redisClient.hmget(pendingGuid, 'names'),
      expirationTime = min(max(data.requestTTL || 9*60, 1), 9*60) * 60;

      redisClient.get(pendingMatchKey, function(err, pendingGuid){
        redisClient.hmget(pendingGuid, 'names', function(err, pendingOpponentNames){
          if(pendingGuid) {
            var matchGuid = createGuid(),
            selectedTableName = tables.pickMatchTable();

            console.log("scheduled match with: " + pendingOpponentNames);

            redisClient.multi()
            .del(pendingMatchKey)
            .hset(pendingGuid, 'scheduledMatchGuid', matchGuid)
            .hset(guid, 'scheduledMatchGuid', matchGuid)
            .hset(pendingGuid, 'confirmed', 0)
            .hset(guid, 'confirmed', 0)
            .hmset(matchGuid, {team1: pendingGuid, team2: guid, tableName: selectedTableName})
            .expire(matchGuid, 40)
            .expire(pendingGuid, 40)
            .expire(guid, 40)
            .exec(repeatFunction);
          } else {
            redisClient.multi()
            .set(newMatchKey, guid)
            .expire(newMatchKey, expirationTime)
{'fraction_non_alphanumeric': 0.12142197599261312, 'fraction_numerical': 0.01061865189289012, 'mean_word_length': 2.6198830409356724, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3675420', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1251, 'n_words': 263}