<commit_before>module.exports = function(req, res) {
  var MAX_REMIXES = 5;
  var make = require("../lib/makeapi");

  function renderError(message) {
    return res.render("details.html", {error:message});
  }

  // Use a URL in the querystring or an ID
  var searchOptions = {},
      searchCriteria;
  if ( req.query.id ) {
    searchCriteria = "id";
    searchOptions.id = req.query.id;
  } else if ( req.query.url ) {
    searchCriteria = "url";
    searchOptions.url = decodeURIComponent( req.query.url );
  } else {
    return renderError("No URL or ID was passed");
  }

  make.find(searchOptions).process( function( err, data ) {
    if ( err ) {
      return renderError("Looks like there is a problem with the make API");
    }
    if ( data && !data.length ) {
      return renderError("No make was found :(");
    }
    var makeData = data[ 0 ];

    // Prep remixes, max of 10
    makeData.remixes( function( err, remixData ) {
      if ( err ) {
        return renderError("Looks like there is a problem with the make API");
      }
      makeData.remixList = [];

      for ( var i = 0; i < Math.min( remixData.length, MAX_REMIXES ); i++ ) {
        makeData.remixList.push({
          url: remixData[ i ].url,
          username: remixData[ i ].username
        });
      }

      if ( remixData.length >= MAX_REMIXES ) {
        makeData.remixCount = remixData.length + "+ remixes";
      } else if ( remixData.length > 1 ) {
        makeData.remixCount = remixData.length + " remixes";
      } else if ( remixData.length === 1 ) {
        makeData.remixCount = "1 remix";
      }

      // Prep original source
      if ( makeData.remixedFrom ) {
        make[ searchCriteria ]( makeData.remixedFrom ).then( function( err, remixedFromData ) {
          if ( err ) {
            return renderError( "Looks like there is a problem with the make API" );
          }

          if ( remixedFromData && remixedFromData.length ) {
            makeData.remixedFromData = {};
            makeData.remixedFromData.url = remixedFromData[ 0 ].url;
            makeData.remixedFromData.username = remixedFromData[ 0 ].username;
          }
          res.render( "details.html", makeData );<commit_msg>Fix Bug 870054 - Implement accurate remix count<commit_after>module.exports = function(req, res) {
  var MAX_REMIXES = 5;
  var make = require("../lib/makeapi");

  function renderError(message) {
    return res.render("details.html", {error:message});
  }

  // Use a URL in the querystring or an ID
  var searchOptions = {},
      searchCriteria;
  if ( req.query.id ) {
    searchCriteria = "id";
    searchOptions.id = req.query.id;
  } else if ( req.query.url ) {
    searchCriteria = "url";
    searchOptions.url = decodeURIComponent( req.query.url );
  } else {
    return renderError("No URL or ID was passed");
  }

  make.find(searchOptions).process( function( err, data ) {
    if ( err ) {
      return renderError("Looks like there is a problem with the make API");
    }
    if ( data && !data.length ) {
      return renderError("No make was found :(");
    }
    var makeData = data[ 0 ];

    // Prep remixes, max of 10
    makeData.remixes( function( err, remixData, totalHits ) {
      if ( err ) {
        return renderError("Looks like there is a problem with the make API");
      }
      makeData.remixList = [];

      for ( var i = 0; i < Math.min( remixData.length, MAX_REMIXES ); i++ ) {
        makeData.remixList.push({
          url: remixData[ i ].url,
          username: remixData[ i ].username
        });
      }

      if ( totalHits === 1 ) {
        makeData.remixCount = "1 remix";
      } else {
        makeData.remixCount = totalHits + " remixes";
      }

      // Prep original source
      if ( makeData.remixedFrom ) {
        make[ searchCriteria ]( makeData.remixedFrom ).then( function( err, remixedFromData ) {
          if ( err ) {
            return renderError( "Looks like there is a problem with the make API" );
          }

          if ( remixedFromData && remixedFromData.length ) {
            makeData.remixedFromData = {};
            makeData.remixedFromData.url = remixedFromData[ 0 ].url;
            makeData.remixedFromData.username = remixedFromData[ 0 ].username;
          }
          res.render( "details.html", makeData );
{'fraction_non_alphanumeric': 0.12293748547524982, 'fraction_numerical': 0.005809900069718801, 'mean_word_length': 2.277989337395278, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5065722', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1316, 'n_words': 355}