From 570f376421e69132542afbd901ed8c49f2c56168 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Wed, 10 Apr 2013 19:24:27 -0400 Subject: [PATCH] more fixes to task corruption --- src/app/index.coffee | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index 9ac09770cc..7e9fac7648 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -22,7 +22,7 @@ _ = require('underscore') ### Cleanup 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 - Gotta love refLists! + Gotta love refLists! see https://github.com/lefnire/habitrpg/issues/803 ### cleanupCorruptTasks = (model) -> user = model.at('_user') @@ -30,24 +30,27 @@ cleanupCorruptTasks = (model) -> ## Remove corrupted tasks _.each tasks, (task, key) -> - unless task?.type? + unless task?.id? and task?.type? user.del("tasks.#{key}") delete tasks[key] ## Task List Cleanup _.each ['habit','daily','todo','reward'], (type) -> - idList = user.get("#{type}Ids") # 1. remove duplicates # 2. restore missing zombie tasks back into list + idList = user.get("#{type}Ids") taskIds = _.pluck( _.where(tasks, {type:type}), 'id') union = _.union idList, taskIds # 2. remove empty (grey) tasks - preened = _.filter union, (val) -> _.contains(taskIds, val) and val? + preened = _.filter union, (id) -> id and _.contains(taskIds, id) # There were indeed issues found, set the new list - user.set("#{type}Ids", preened) if _.difference(preened, idList).length != 0 + wasCorrupted = !_.isEmpty _.difference(idList, preened) + if wasCorrupted + user.set("#{type}Ids", preened) + console.error user.get('id') + "'s #{type}s were corrupt." get '/', (page, model, params, next) -> return page.redirect '/' if page.params?.query?.play?