BREAKING CHANGE! this removes list cleanup / re-establishment. In the past, id-lists in refLists were being completely emptied (see #85 & #86). I'm still not sure why (see https://github.com/codeparty/racer/issues/101 or https://github.com/codeparty/derby/issues/237 possibly?). This commit reverts working around that issue, but potentially fixes #769. Going to test this on heroku a bit before merging in
This commit is contained in:
@@ -2,12 +2,6 @@ _ = require 'underscore'
|
||||
moment = require 'moment'
|
||||
#algos = require './algos'
|
||||
|
||||
|
||||
restoreRefs = module.exports.restoreRefs = (model) ->
|
||||
#refLists
|
||||
_.each ['habit', 'daily', 'todo', 'reward'], (type) ->
|
||||
model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids"
|
||||
|
||||
###
|
||||
Loads JavaScript files from public/js/*
|
||||
If a library is available in a CDN, we put it in <Scripts:> (index.html) for better caching. If not, we use
|
||||
|
||||
@@ -137,38 +137,6 @@ module.exports.newUserObject = ->
|
||||
when 'reward' then newUser.rewardIds.push guid
|
||||
return newUser
|
||||
|
||||
module.exports.updateUser = (model) ->
|
||||
batch = new BatchUpdate(model)
|
||||
user = batch.user
|
||||
obj = batch.obj()
|
||||
tasks = obj.tasks
|
||||
|
||||
# Remove corrupted tasks
|
||||
_.each tasks, (task, key) ->
|
||||
unless task?
|
||||
user.del("tasks.#{key}")
|
||||
delete tasks[key]
|
||||
|
||||
batch.startTransaction()
|
||||
|
||||
batch.set('apiToken', derby.uuid()) unless obj.apiToken
|
||||
|
||||
## Task List Cleanup
|
||||
# FIXME temporary hack to fix lists (Need to figure out why these are happening)
|
||||
_.each ['habit','daily','todo','reward'], (type) ->
|
||||
# 1. remove duplicates
|
||||
# 2. restore missing zombie tasks back into list
|
||||
taskIds = _.pluck( _.where(tasks, {type:type}), 'id')
|
||||
union = _.union obj[type + 'Ids'], taskIds
|
||||
|
||||
# 2. remove empty (grey) tasks
|
||||
preened = _.filter union, (val) -> _.contains(taskIds, val) and val?
|
||||
|
||||
# There were indeed issues found, set the new list
|
||||
batch.set("#{type}Ids", preened) # if _.difference(preened, userObj[path]).length != 0
|
||||
|
||||
batch.commit()
|
||||
|
||||
module.exports.BatchUpdate = BatchUpdate = (model) ->
|
||||
user = model.at("_user")
|
||||
transactionInProgress = false
|
||||
|
||||
+12
-2
@@ -41,10 +41,20 @@ get '/', (page, model, params, next) ->
|
||||
# return page.redirect 'https://' + req.headers.host + req.url
|
||||
|
||||
party.partySubscribe page, model, params, next, ->
|
||||
character.updateUser(model)
|
||||
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?
|
||||
|
||||
items.server(model)
|
||||
model.set '_view', _view
|
||||
browser.restoreRefs model
|
||||
|
||||
#refLists
|
||||
_.each ['habit', 'daily', 'todo', 'reward'], (type) ->
|
||||
model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids"
|
||||
|
||||
page.render()
|
||||
|
||||
# ========== CONTROLLER FUNCTIONS ==========
|
||||
|
||||
Reference in New Issue
Block a user