From cc097c32f755cdd17ee49033d9565c6ead8b0390 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Tue, 21 May 2013 12:53:05 +0100 Subject: [PATCH] clean up of preen_cron, which I'm re-enstating --- migrations/20130212_preen_cron.js | 36 ++++++++++++++----------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/migrations/20130212_preen_cron.js b/migrations/20130212_preen_cron.js index fc45cc0f13..59c74ed911 100644 --- a/migrations/20130212_preen_cron.js +++ b/migrations/20130212_preen_cron.js @@ -12,17 +12,16 @@ */ var un_registered = { - "auth.local": {$exists: false}, - "auth.facebook": {$exists: false} -}; -var registered = { - $or: [ - { 'auth.local': { $exists: true }}, - { 'auth.facebook': { $exists: true }} - ] -}; - -var today = +(new Date); + "auth.local": {$exists: false}, + "auth.facebook": {$exists: false} + }, + registered = { + $or: [ + { 'auth.local': { $exists: true }}, + { 'auth.facebook': { $exists: true }} + ] + }, + today = +new Date; // isValidDate = (d) -> // return false if Object::toString.call(d) isnt "[object Date]" @@ -30,12 +29,9 @@ var today = +(new Date); db.users.find(un_registered).forEach(function(user) { - var diff, lastCron; if (!user) return; if (!!user.lastCron) { - lastCron = new Date(user.lastCron); - diff = Math.abs(moment(today).startOf('day').diff(moment(lastCron).startOf('day'), "days")); - if (diff > 3) { + if (Math.abs(moment(today).diff(user.lastCron, 'd')) > 5) { return db.users.remove({_id:user._id}); } } else { @@ -49,8 +45,8 @@ db.users.find(un_registered).forEach(function(user) { * revisit if needs be */ /*db.sessions.find().forEach(function(sess){ - var uid = JSON.parse(sess.session).userId; - if (!uid || db.users.count({_id:uid}) === 0) { - db.sessions.remove({_id:sess._id}); - } -});*/ \ No newline at end of file + var uid = JSON.parse(sess.session).userId; + if (!uid || db.users.count({_id:uid}) === 0) { + db.sessions.remove({_id:sess._id}); + } + });*/ \ No newline at end of file