From 5de226915712e2af60fa0a374c7c6b2bb868a6a4 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Wed, 29 May 2013 23:06:07 +0100 Subject: [PATCH 1/4] hotfix: getting a lot of "DERBY is not defined" --- src/app/browser.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/browser.coffee b/src/app/browser.coffee index 685621c993..44dcedb810 100644 --- a/src/app/browser.coffee +++ b/src/app/browser.coffee @@ -195,8 +195,8 @@ setupGrowlNotifications = (model) -> statsNotification ' Level Up!', 'lvl' module.exports.resetDom = (model) -> - DERBY.app.dom.clear() - DERBY.app.view.render(model, DERBY.app.view._lastRender.ns, DERBY.app.view._lastRender.context); + window.DERBY.app.dom.clear() + window.DERBY.app.view.render(model, window.DERBY.app.view._lastRender.ns, window.DERBY.app.view._lastRender.context); # Note, Google Analyatics giving beef if in this file. Moved back to index.html. It's ok, it's async - really the # syncronous requires up top are what benefit the most from this file. From b4a5688cddcc4c7961d1ee140e58e8782d0790de Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Thu, 30 May 2013 18:07:00 +0100 Subject: [PATCH 2/4] return delta bug fix --- src/app/misc.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/misc.coffee b/src/app/misc.coffee index 787816d6ef..2e427a951d 100644 --- a/src/app/misc.coffee +++ b/src/app/misc.coffee @@ -11,7 +11,7 @@ module.exports.batchTxn = batchTxn = (model, cb, options) -> get: (k) -> helpers.dotGet(k,uObj) paths = {} model._dontPersist = true - cb uObj, paths, batch + ret = cb uObj, paths, batch _.each paths, (v,k) -> user.pass({cron:options?.cron}).set(k,helpers.dotGet(k, uObj));true model._dontPersist = false # some hackery in our own branched racer-db-mongo, see findAndModify of lefnire/racer-db-mongo#habitrpg index.js @@ -19,6 +19,8 @@ module.exports.batchTxn = batchTxn = (model, cb, options) -> unless _.isEmpty paths setOps = _.reduce paths, ((m,v,k)-> m[k] = helpers.dotGet(k,uObj);m), {} user.set "update__", setOps + ret + ### algos.score wrapper for habitrpg-helpers to work in Derby. We need to do model.set() instead of simply setting the From dae3ca635fe833d3fc08c28a93d0234d65524ee7 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Thu, 30 May 2013 14:54:00 -0400 Subject: [PATCH 3/4] duplicate pets being pushed into stable, fixes #1086 --- src/app/index.coffee | 38 +------------------------------------- src/app/misc.coffee | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index ad63683073..ec5772a4dc 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -22,42 +22,6 @@ misc.viewHelpers view _ = require('lodash') algos = require 'habitrpg-shared/script/algos' -helpers = require 'habitrpg-shared/script/helpers' - -### - 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! see https://github.com/lefnire/habitrpg/issues/803 & https://github.com/lefnire/habitrpg/issues/6343 -### -cleanupCorruptTasks = (model) -> - user = model.at('_user') - tasks = user.get('tasks') - - ## Remove corrupted tasks - _.each tasks, (task, key) -> - unless task?.id? and task?.type? - user.del("tasks.#{key}") - delete tasks[key] - true - - misc.batchTxn model, (uObj, paths, batch) -> - ## Task List Cleanup - ['habit','daily','todo','reward'].forEach (type) -> - - # 1. remove duplicates - # 2. restore missing zombie tasks back into list - idList = uObj["#{type}Ids"] - taskIds = _.pluck( _.where(tasks, {type:type}), 'id') - union = _.union idList, taskIds - - # 2. remove empty (grey) tasks - preened = _.filter union, (id) -> id and _.contains(taskIds, id) - - # There were indeed issues found, set the new list - if !_.isEqual(idList, preened) - batch.set("#{type}Ids", preened) - console.error uObj.id + "'s #{type}s were corrupt." - true ### @@ -103,7 +67,7 @@ get '/', (page, model, params, next) -> # removed force-ssl (handled in nginx), see git for code setupSubscriptions page, model, params, next, -> - cleanupCorruptTasks(model) # https://github.com/lefnire/habitrpg/issues/634 + misc.fixCorruptUser(model) # https://github.com/lefnire/habitrpg/issues/634 require('./items').server(model) #refLists _.each ['habit', 'daily', 'todo', 'reward'], (type) -> diff --git a/src/app/misc.coffee b/src/app/misc.coffee index 2e427a951d..e2b0743aa0 100644 --- a/src/app/misc.coffee +++ b/src/app/misc.coffee @@ -60,6 +60,48 @@ module.exports.hydrate = hydrate = (spec) -> hydrated else spec + +### + 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! see https://github.com/lefnire/habitrpg/issues/803 & https://github.com/lefnire/habitrpg/issues/6343 +### +module.exports.fixCorruptUser = (model) -> + user = model.at('_user') + tasks = user.get('tasks') + + ## Remove corrupted tasks + _.each tasks, (task, key) -> + unless task?.id? and task?.type? + user.del("tasks.#{key}") + delete tasks[key] + true + + batchTxn model, (uObj, paths, batch) -> + + ## fix https://github.com/lefnire/habitrpg/issues/1086 + uniqPets = _.uniq(uObj.items.pets) + batch.set('items.pets', uniqPets) if !_.isEqual(uniqPets, uObj.items.pets) + console.log {uniqPets, count:_.size(uniqPets)} + + ## Task List Cleanup + ['habit','daily','todo','reward'].forEach (type) -> + + # 1. remove duplicates + # 2. restore missing zombie tasks back into list + idList = uObj["#{type}Ids"] + taskIds = _.pluck( _.where(tasks, {type:type}), 'id') + union = _.union idList, taskIds + + # 2. remove empty (grey) tasks + preened = _.filter union, (id) -> id and _.contains(taskIds, id) + + # There were indeed issues found, set the new list + if !_.isEqual(idList, preened) + batch.set("#{type}Ids", preened) + console.error uObj.id + "'s #{type}s were corrupt." + true + module.exports.viewHelpers = (view) -> #misc From 9399ca1d9848707ba9946166520aac1aa14776cc Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Thu, 30 May 2013 14:56:28 -0400 Subject: [PATCH 4/4] remove console.log --- src/app/misc.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/misc.coffee b/src/app/misc.coffee index e2b0743aa0..b0428bd9b0 100644 --- a/src/app/misc.coffee +++ b/src/app/misc.coffee @@ -82,7 +82,6 @@ module.exports.fixCorruptUser = (model) -> ## fix https://github.com/lefnire/habitrpg/issues/1086 uniqPets = _.uniq(uObj.items.pets) batch.set('items.pets', uniqPets) if !_.isEqual(uniqPets, uObj.items.pets) - console.log {uniqPets, count:_.size(uniqPets)} ## Task List Cleanup ['habit','daily','todo','reward'].forEach (type) ->