<commit_before>var config = require("../config.json");
var redis = require("redis");
var Citation = require("citation.js");

var client = redis.createClient();

client.on("error", function(err) {
  console.error(err);
});

module.exports.cite = function(req, res) {
  var query = req.query.q;
  var host;

  if (!(/\w+/.test(query))) {
    res.send(400, "Bad query");
  }

  if (!(/^https?/.test(query))) {
    host = "http://" + query;
  }
  else {
    host = query;
  }

  var citation = new Citation(host);

  client.get(host, function(err, ref) {
    if (ref) {
      return res.send(ref);
    }

    citation.getMlaReference(function(err, ref) {
      if (err) {
        return res.send(500, err) && console.log(err);
      }

      if (!ref) {
        return res.send(500, "Bad reference");
      }

      client.set(host, ref);
      client.expire(host, 1e3 * 60 * 60 * 24); // 1 day
      res.send(ref);
    });
  });
};

module.exports.cached = function(req, res) {
  client.keys("*", function(err, keys) {
    if (!err) {
      res.send(keys.filter(function(key) {
        // Redis databases can leak session ids (like my testing DB now ;)<commit_msg>Redis takes seconds, not milliseconds. Oops.<commit_after>var config = require("../config.json");
var redis = require("redis");
var Citation = require("citation.js");

var client = redis.createClient();

client.on("error", function(err) {
  console.error(err);
});

module.exports.cite = function(req, res) {
  var query = req.query.q;
  var host;

  if (!(/\w+/.test(query))) {
    res.send(400, "Bad query");
  }

  if (!(/^https?/.test(query))) {
    host = "http://" + query;
  }
  else {
    host = query;
  }

  var citation = new Citation(host);

  client.get(host, function(err, ref) {
    if (ref) {
      return res.send(ref);
    }

    citation.getMlaReference(function(err, ref) {
      if (err) {
        return res.send(500, err) && console.log(err);
      }

      if (!ref) {
        return res.send(500, "Bad reference");
      }

      client.set(host, ref);
      client.expire(host, 1 * 60 * 60 * 24 * 2); // 2 days
      res.send(ref);
    });
  });
};

module.exports.cached = function(req, res) {
  client.keys("*", function(err, keys) {
    if (!err) {
      res.send(keys.filter(function(key) {
        // Redis databases can leak session ids (like my testing DB now ;)
{'fraction_non_alphanumeric': 0.18505942275042445, 'fraction_numerical': 0.015280135823429542, 'mean_word_length': 2.6373456790123457, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6770504', 'n_tokens_mistral': 868, 'n_tokens_neox': 813, 'n_words': 188}