user.setNull for lastCron right away, to avoid missing lastCrons

This commit is contained in:
Tyler Renelle
2013-01-28 14:04:10 -05:00
parent d888d879d8
commit b4e8d1e69a
2 changed files with 4 additions and 4 deletions
+3 -2
View File
@@ -102,7 +102,7 @@ cron = (model) ->
# This is an expensive function, only call it on cron
lastCron = user.get('lastCron')
return unless !lastCron or (helpers.daysBetween(new Date(), lastCron) > 0)
return unless helpers.daysBetween(+new Date, lastCron) > 0
userObj = user.get()
@@ -118,6 +118,7 @@ cron = (model) ->
ready (model) ->
user = model.at('_user')
user.setNull 'lastCron', +new Date #set cron immediately
# Setup model in scoring functions
scoring.setModel(model)
@@ -236,7 +237,7 @@ ready (model) ->
matrix = [['Date', 'Score']]
for obj in model.get(historyPath)
date = new Date(obj.date)
date = +new Date(obj.date)
readableDate = moment(date).format('MM/DD')
matrix.push [ readableDate, obj.value ]
data = google.visualization.arrayToDataTable matrix
+1 -2
View File
@@ -144,7 +144,7 @@ score = (taskId, direction, times, update) ->
adjustvalue = if (taskObj.up==false or taskObj.down==false) then false else true
calculateDelta(adjustvalue)
# Add habit value to habit-history (if different)
historyEntry = { date: new Date(), value: value } if taskObj.value != value
historyEntry = { date: +new Date(), value: value } if taskObj.value != value
if (delta > 0) then addPoints() else subtractPoints()
model.push "_user.#{taskPath}.history", historyEntry
@@ -181,7 +181,6 @@ score = (taskId, direction, times, update) ->
###
cron = (userObj) ->
today = +new Date
userObj.lastCron ?= today
daysPassed = helpers.daysBetween(today, userObj.lastCron)
if daysPassed > 0
# Tally each task