give all tasks a creation date. When to-dos are completed, if they're

sitting in "completed" section for more than 3 days, delete them on
cron. @sabrecat @paglias @colegleason @wc8 heads up. this should help
with the performance issues people are experiencing when they don't know
to clear completeds, but let me know if this you think this is a bad
idea. @wizonesolutions sorry for the delay ;)
This commit is contained in:
Tyler Renelle 2014-01-14 16:42:41 -07:00
parent e4d1451756
commit d3a076a405
3 changed files with 37 additions and 8 deletions

View file

@ -10162,7 +10162,7 @@ var global=self;/**
thing and receives another, it will cause errors. `self` is used for self buffs, multi-task debuffs, AOEs (eg, meteor-shower),
etc. Basically, use self for anything that's not [task, party, user] and is an instant-cast
* {cast}: the fucntion that's run to perform the ability's action. This is pretty slick - because this is exported to the
* {cast}: the function that's run to perform the ability's action. This is pretty slick - because this is exported to the
web, this function can be performed on the client and on the server. `user` param is self (needed for determining your
own stats for effectiveness of cast), and `target` param is one of [task, party, user]. In the case of `self` spells,
you act on `user` instead of `target`. You can trust these are the correct objects, as long as the `target` attr of the
@ -10857,16 +10857,12 @@ var process=require("__browserify_process");(function() {
};
api.startOfDay = function(options) {
var dayStart, o;
var o;
if (options == null) {
options = {};
}
o = sanitizeOptions(options);
dayStart = moment(o.now).startOf('day').add('h', o.dayStart);
if (moment(o.now).isBefore(dayStart)) {
dayStart.subtract('day', 1);
}
return dayStart;
return moment(o.now).startOf('day').add('h', o.dayStart);
};
dayMapping = {
@ -11093,7 +11089,8 @@ var process=require("__browserify_process");(function() {
notes: '',
priority: 1,
challenge: {},
attribute: 'str'
attribute: 'str',
created: new Date()
};
_.defaults(task, defaults);
if (task.type === 'habit') {
@ -12407,6 +12404,9 @@ var process=require("__browserify_process");(function() {
if (user.stats.mp > user._statsComputed.maxMP) {
user.stats.mp = user._statsComputed.maxMP;
}
user.todos = _.where(user.todos, function(t) {
return !t.completed || moment(t.created).isAfter(moment().subtract('days', 3));
});
if (user.preferences.sleep === true) {
user.stats.buffs = {
str: 0,

View file

@ -177,6 +177,7 @@ api.taskDefaults = (task={}) ->
priority: 1
challenge: {}
attribute: 'str'
created: new Date()
_.defaults task, defaults
_.defaults(task, {up:true,down:true}) if task.type is 'habit'
_.defaults(task, {history: []}) if task.type in ['habit', 'daily']
@ -1135,6 +1136,9 @@ api.wrap = (user, main=true) ->
user.stats.mp += _.max([10,.1 * user._statsComputed.maxMP])
user.stats.mp = user._statsComputed.maxMP if user.stats.mp > user._statsComputed.maxMP
user.todos = _.where user.todos, (t) ->
!t.completed or moment(t.created).isAfter(moment().subtract('days',3))
# User is resting at the inn. Used to be we un-checked each daily without performing calculation (see commits before fb29e35)
# but to prevent abusing the inn (http://goo.gl/GDb9x) we now do *not* calculate dailies, and simply set lastCron to today
if user.preferences.sleep is true

View file

@ -137,6 +137,31 @@ describe 'User', ->
user.items.gear.equipped.weapon = 'weapon_wizard_1'
expect(user._statsComputed.maxMP).to.eql 63
it 'Clears old To-Dos', ->
user = newUser()
shared.wrap(user)
cron = -> user.lastCron = moment().subtract('days',1);user.fns.cron({})
user.todos = []
_.times 3, (i)-> user.todos.push shared.taskDefaults({type:'todo',text:i})
# Fresh todos, no change
cron()
expect(_.size(user.todos)).to.be 3
# Complete Todos, no change
_.each user.todos, (t)->t.created = moment().subtract('days',4)
cron()
expect(_.size(user.todos)).to.be 3
user.todos[0].completed = true
user.todos[1].completed = true
cron()
expect(_.size(user.todos)).to.be 1
user.todos[0].completed = true
cron()
expect(_.size(user.todos)).to.be 0
describe 'Death', ->
user = undefined
it 'revives correctly', ->