mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-31 23:11:15 +00:00
move task-corruption cleanup to cron, restore missing tasks to list -
let's see if this fixes #777
This commit is contained in:
parent
6522badaa6
commit
9222b56777
2 changed files with 12 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue