mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 18:22:21 +00:00
updateSchema to remove inactive users, reset history
This commit is contained in:
parent
c5bbc67f05
commit
8dfa4a862b
2 changed files with 68 additions and 13 deletions
|
|
@ -21,4 +21,41 @@ module.exports.userSchema = userSchema = {
|
|||
rewardIds: []
|
||||
};
|
||||
|
||||
module.exports.updateSchema = function(model) {};
|
||||
module.exports.updateSchema = function(model) {
|
||||
return model.fetch('users', function(err, users) {
|
||||
return _.each(users.get(), function(userObj) {
|
||||
var daysOld, sameTasks, user, userPath;
|
||||
userPath = "users." + userObj._id;
|
||||
user = model.at(userPath);
|
||||
if (userObj.lastCron == null) {
|
||||
model.del(userPath);
|
||||
return;
|
||||
}
|
||||
daysOld = require('./helpers').daysBetween(userObj.lastCron, new Date());
|
||||
if (daysOld > 30) {
|
||||
sameTasks = _.filter(require('./content').defaultTasks, function(defaultTask) {
|
||||
var foundSame;
|
||||
foundSame = _.find(userObj.tasks, function(userTask) {
|
||||
return userTask.text === defaultTask.text;
|
||||
});
|
||||
return foundSame != null;
|
||||
});
|
||||
if (_.size(sameTasks) > 5) {
|
||||
model.del(userPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
user.set('history', {
|
||||
exp: [],
|
||||
todos: []
|
||||
});
|
||||
return _.each(userObj.tasks, function(taskObj) {
|
||||
var task;
|
||||
task = user.at("tasks." + taskObj.id);
|
||||
if (task.get("history")) {
|
||||
return task.set("history", []);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,15 +11,33 @@ module.exports.userSchema = userSchema = {
|
|||
}
|
||||
|
||||
module.exports.updateSchema = (model) ->
|
||||
# users = model.get('users')
|
||||
# console.log _.size(users), 'users.size before'
|
||||
# for uid,userObj of users
|
||||
# # remove if they don't have a lastCron (older accounts didn't)
|
||||
# unless userObj.lastCron?
|
||||
# model.del "users.#{uid}"
|
||||
|
||||
# TODO remove all users who's tasks compare directly to require('./content).defaultTasks
|
||||
# and haven't logged in for a week
|
||||
# daysOld = require('./helpers').daysBetween(userObj.lastCron, new Date())
|
||||
|
||||
|
||||
# Reset history, remove inactive users
|
||||
model.fetch 'users', (err, users) ->
|
||||
_.each users.get(), (userObj) ->
|
||||
userPath = "users.#{userObj._id}"
|
||||
user = model.at(userPath)
|
||||
|
||||
# Remove inactive users
|
||||
# remove if they don't have a lastCron (older accounts didn't)
|
||||
unless userObj.lastCron?
|
||||
model.del(userPath)
|
||||
return
|
||||
|
||||
# Remove all users who haven't logged in for a month
|
||||
daysOld = require('./helpers').daysBetween(userObj.lastCron, new Date())
|
||||
if daysOld > 30
|
||||
# and who have mostly the default tasks
|
||||
sameTasks = _.filter require('./content').defaultTasks, (defaultTask) ->
|
||||
foundSame = _.find userObj.tasks, (userTask) ->
|
||||
userTask.text == defaultTask.text
|
||||
return foundSame?
|
||||
if _.size(sameTasks)>5
|
||||
model.del(userPath)
|
||||
return
|
||||
|
||||
# Reset all history
|
||||
user.set 'history', {exp:[], todos:[]}
|
||||
_.each userObj.tasks, (taskObj) ->
|
||||
task = user.at "tasks.#{taskObj.id}"
|
||||
if task.get("history")
|
||||
task.set "history", []
|
||||
Loading…
Reference in a new issue