<commit_before>
var config = require('./config.js'),
    algo = require('./algorithms.js');
    async = require('async');
    
var updateSequence = function(userId, itemId, update, callback){
  if (typeof update == 'function') {
    callback = update;
    update = true;
  }
  if (update) {
    async.parallel([
      function(cb){
        algo.updateItem(itemId, function(){
          cb(null);
        });
      },
      function(cb){
        algo.updateUser(userId, function(){
          cb(null);
        });
      }
    ],
    function(err){
      if (err){console.log('error', err);}
      callback();
    });
  }
};

var input = {
  liked: function(userId, itemId, update, callback){
    client.sismember([config.className, 'item', itemId, 'liked'].join(":"), userId, function(err, results){
      if (results === 0){
        client.zincrby([config.className, 'mostLiked'].join(":"), 1, itemId);
      }
      client.sadd([config.className, 'user', userId,'liked'].join(':'), itemId, function(err){
        client.sadd([config.className, 'item', itemId, 'liked'].join(':'), userId, function(err){
          updateSequence(userId, itemId, update, callback);
        });
      });
    });
  },
  disliked: function(userId, itemId, update, callback){
    client.sismember([config.className, 'item', itemId, 'disliked'].join(":"), userId, function(err, results){
      if (results === 0){
        client.zincrby([config.className, 'mostDisliked'].join(":"), 1, itemId);
      }
      client.sadd([config.className, 'user', userId, 'disliked'].join(':'), itemId, function(err){
        client.sadd([config.className, 'item', itemId, 'disliked'].join(':'), userId, function(err){
          updateSequence(userId, itemId, update, callback);
        });
      });
    });
  }
};

module.exports = input;

<commit_msg>Added explanation for the update parameter switch<commit_after>
var config = require('./config.js'),
    algo = require('./algorithms.js');
    async = require('async');
    
var updateSequence = function(userId, itemId, update, callback){
  //make the update parameter optional while still allowing the callback to be last (for readability)
  if (typeof update == 'function') {
    callback = update;
    update = true;
  }
  if (update) {
    async.parallel([
      function(cb){
        algo.updateItem(itemId, function(){
          cb(null);
        });
      },
      function(cb){
        algo.updateUser(userId, function(){
          cb(null);
        });
      }
    ],
    function(err){
      if (err){console.log('error', err);}
      callback();
    });
  }
};

var input = {
  liked: function(userId, itemId, update, callback){
    client.sismember([config.className, 'item', itemId, 'liked'].join(":"), userId, function(err, results){
      if (results === 0){
        client.zincrby([config.className, 'mostLiked'].join(":"), 1, itemId);
      }
      client.sadd([config.className, 'user', userId,'liked'].join(':'), itemId, function(err){
        client.sadd([config.className, 'item', itemId, 'liked'].join(':'), userId, function(err){
          updateSequence(userId, itemId, update, callback);
        });
      });
    });
  },
  disliked: function(userId, itemId, update, callback){
    client.sismember([config.className, 'item', itemId, 'disliked'].join(":"), userId, function(err, results){
      if (results === 0){
        client.zincrby([config.className, 'mostDisliked'].join(":"), 1, itemId);
      }
      client.sadd([config.className, 'user', userId, 'disliked'].join(':'), itemId, function(err){
        client.sadd([config.className, 'item', itemId, 'disliked'].join(':'), userId, function(err){
          updateSequence(userId, itemId, update, callback);
        });
      });
    });
  }
};

module.exports = input;


{'fraction_non_alphanumeric': 0.18885941644562335, 'fraction_numerical': 0.002122015915119363, 'mean_word_length': 3.0202558635394454, 'pattern_counts': {'":': 8, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6219688', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1164, 'n_words': 243}