mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
use lean and .update
This commit is contained in:
parent
808885425f
commit
ce03f837c7
1 changed files with 10 additions and 7 deletions
|
|
@ -8,23 +8,25 @@ let count = 0;
|
|||
async function updateUser (user) {
|
||||
count++;
|
||||
|
||||
user.migration = MIGRATION_NAME;
|
||||
const set = {};
|
||||
|
||||
set.migration = MIGRATION_NAME;
|
||||
|
||||
if (user.items.pets['Bear-Veteran']) {
|
||||
user.items.pets['Fox-Veteran'] = 5;
|
||||
set['items.pets.Fox-Veteran'] = 5;
|
||||
} else if (user.items.pets['Lion-Veteran']) {
|
||||
user.items.pets['Bear-Veteran'] = 5;
|
||||
set['items.pets.Bear-Veteran'] = 5;
|
||||
} else if (user.items.pets['Tiger-Veteran']) {
|
||||
user.items.pets['Lion-Veteran'] = 5;
|
||||
set['items.pets.Lion-Veteran'] = 5;
|
||||
} else if (user.items.pets['Wolf-Veteran']) {
|
||||
user.items.pets['Tiger-Veteran'] = 5;
|
||||
set['items.pets.Tiger-Veteran'] = 5;
|
||||
} else {
|
||||
user.items.pets['Wolf-Veteran'] = 5;
|
||||
set['items.pets.Wolf-Veteran'] = 5;
|
||||
}
|
||||
|
||||
if (count % progressCount === 0) console.warn(`${count} ${user._id}`);
|
||||
|
||||
return await user.save();
|
||||
return await User.update({_id: user._id}, {$set: set}).exec();
|
||||
}
|
||||
|
||||
module.exports = async function processUsers () {
|
||||
|
|
@ -46,6 +48,7 @@ module.exports = async function processUsers () {
|
|||
.limit(250)
|
||||
.sort({_id: 1})
|
||||
.select(fields)
|
||||
.lean()
|
||||
.exec();
|
||||
|
||||
if (users.length === 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue