<commit_before>var less = require('less')
   ,Q    = require('q')
   ,parserOptions = require('./parser-options.js')
   ,expireTime = 60 * 60 * 1000 // one hour

module.exports = function() {
   var sessions = {};
   return {
      create: getOrCreateAst,
      get: getSession
   };

   function getOrCreateAst(lessCode) {
      var token = md5(lessCode);
      
      return Q.when(getSession(token) || createSession(lessCode, token));
   }

   function createSession(lessCode, token) {
      return parseLess(lessCode).then(function(syntaxTree) {
         sessions[token] = {
            token: token,
            ast: syntaxTree,
            expires: getExpires()
         };
         return sessions[token];
      });
   }

   function getSession(token) {
      var session = sessions[token];

      if (session) {
         session.expires = getExpires();
      }

      return session;
   }

   // Setup session expiration
   setInterval(function() {
      var now = Date.now();
      Object.keys(sessions).forEach(function(token) {
         if (sessions[token].expires > now) {
            delete sessions[token];
         }
      });
   }, 60 * 1000);
}


function parseLess(body) {
   var deferred = Q.defer()
   var parser = new less.Parser(parserOptions);
   parser.parse(body, deferred.makeNodeResolver());
   return deferred.promise;
}

function md5(string) {
   var crypto = require('crypto');
   var hasher = crypto.createHash('md5');
   hasher.update(string);
   return hasher.digest('base64');
}

function getExpires() {
   return Date.now() + expireTime;
}
<commit_msg>Sessions: fix unreachable code<commit_after>var less = require('less')
   ,Q    = require('q')
   ,parserOptions = require('./parser-options.js')
   ,expireTime = 60 * 60 * 1000 // one hour

module.exports = function() {
   var sessions = {};

   function getOrCreateAst(lessCode) {
      var token = md5(lessCode);
      
      return Q.when(getSession(token) || createSession(lessCode, token));
   }

   function createSession(lessCode, token) {
      return parseLess(lessCode).then(function(syntaxTree) {
         sessions[token] = {
            token: token,
            ast: syntaxTree,
            expires: getExpires()
         };
         return sessions[token];
      });
   }

   function getSession(token) {
      var session = sessions[token];

      if (session) {
         session.expires = getExpires();
      }

      return session;
   }

   // Setup session expiration
   setInterval(function() {
      var now = Date.now();
      Object.keys(sessions).forEach(function(token) {
         if (sessions[token].expires > now) {
            delete sessions[token];
         }
      });
   }, 60 * 1000);

   return {
      create: getOrCreateAst,
      get: getSession
   };
}


function parseLess(body) {
   var deferred = Q.defer()
   var parser = new less.Parser(parserOptions);
   parser.parse(body, deferred.makeNodeResolver());
   return deferred.promise;
}

function md5(string) {
   var crypto = require('crypto');
   var hasher = crypto.createHash('md5');
   hasher.update(string);
   return hasher.digest('base64');
}

function getExpires() {
   return Date.now() + expireTime;
}

{'fraction_non_alphanumeric': 0.1325187969924812, 'fraction_numerical': 0.011904761904761904, 'mean_word_length': 2.5281767955801104, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1242028', 'n_tokens_mistral': 1009, 'n_tokens_neox': 947, 'n_words': 203}