<commit_before>#!/usr/bin/env node

/*
 * Run this script to delete makes that have been marked deleted more than 2 weeks before the current date
 */

var TWO_WEEKS = 1000*60*60*24*14;

var habitat = require( "habitat" ),
    async = require( "async" ),
    mongoose,
    env;

habitat.load();

env = new habitat();

dbh = require( "../lib/mongoose" )( env, function( err ) {
  if ( err ) {
    console.log( err );
    process.exit( 1 );
  }

  var Make = require( "../lib/models/make" )( env, dbh.mongoInstance() ),
      numDeleted = 0,
      queue;

  Make.find({
    deletedAt: {
      "$ne": null,
      "$lt": Date.now() - TWO_WEEKS
    }
  }, function( err, makes ) {
    if ( err || !makes ) {
      console.error( "Error: ", err || "Makes array is null" );
      process.exit( 1 )
    }

    if ( !makes.length ) {
      console.log( "No Makes to Delete" );
      process.exit( 0 );
    }

    queue = async.queue(function( make, callback ) {
      make.remove(function( err ) {
        callback( err || null );
      });
    }, 1 );

    queue.drain = function() {
      console.log( numDeleted + " Makes deleted successfully." );
      process.exit( 0 );
    };

    queue.push( makes, function( err ) {
      if ( err ) {
        return console.error( "Error Deleting Make: ", err );
      }
      numDeleted++;
    });
  });<commit_msg>Simplify cleanup script<commit_after>#!/usr/bin/env node

/*
 * Run this script to delete makes that have been marked deleted more than 2 weeks before the current date
 */

var TWO_WEEKS = 1000*60*60*24*14;

var async = require( "async" );

dbh = require( "../lib/mongoose" )( function( err ) {
  if ( err ) {
    console.log( err );
    process.exit( 1 );
  }

  var Make = require( "../lib/models/make" )( dbh.mongoInstance() ),
      numDeleted = 0,
      queue;

  Make.remove({
    deletedAt: {
      "$ne": null,
      "$lt": Date.now() - TWO_WEEKS
    }
  }, function( err ) {
    if ( err ) {
      console.error( "Error: ", err || "Makes array is null" );
      process.exit( 1 )
    }

    process.exit( 0 );
  });
{'fraction_non_alphanumeric': 0.16353111432706222, 'fraction_numerical': 0.017366136034732273, 'mean_word_length': 2.240625, 'pattern_counts': {'":': 4, '<': 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': '3697478', 'n_tokens_mistral': 741, 'n_tokens_neox': 702, 'n_words': 192}