move task-corruption cleanup to cron, restore missing tasks to list -

let's see if this fixes #777
This commit is contained in:
Tyler Renelle 2013-04-07 20:38:28 -04:00
parent 6522badaa6
commit 9222b56777
2 changed files with 12 additions and 4 deletions

View file

@ -34,10 +34,6 @@ get '/', (page, model, params, next) ->
user = model.at('_user')
user.setNull('apiToken', derby.uuid())
# Remove corrupted tasks
tasks = user.get('tasks')
_.each tasks, (task, key) -> user.del("tasks.#{key}") unless task?
require('./items').server(model)
model.set '_view', _view

View file

@ -260,6 +260,18 @@ cron = (model) ->
today = +new Date
daysPassed = helpers.daysBetween(user.get('lastCron'), today, user.get('preferences.dayStart'))
if daysPassed > 0
# Cleanup some task-corruption (null tasks, rogue/invisible tasks, etc)
# Obviously none of this should be happening, but we'll stop-gap until we can find & fix
tasks = user.get('tasks')
_.each tasks, (task, key) ->
# Remove null tasks
unless task?
user.del("tasks.#{key}")
# Put rogue tasks back into their lists. We could alternatively delete them (they're rogue because they weren't properly deleted), but that's dangerous
if user.get("#{task.type}Ids").indexOf(task.id) is -1
user.push "#{task.type}Ids", task.id
batch = new character.BatchUpdate(model)
batch.startTransaction()
batch.set 'lastCron', today