forked from HabitRPG/habitica
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a34a75d
commit b7dc78f
Showing
6 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
migrations/archive/2024/20240516_pet_group_achievements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* eslint-disable no-console */ | ||
const MIGRATION_NAME = '202405_pet_group_achievements'; | ||
import { model as User } from '../../../website/server/models/user'; | ||
|
||
const progressCount = 1000; | ||
let count = 0; | ||
|
||
async function updateUser (user) { | ||
count++; | ||
|
||
let set = { | ||
migration: MIGRATION_NAME, | ||
}; | ||
|
||
if (user && user.items && user.items.pets) { | ||
const pets = user.items.pets; | ||
if (pets['Lion-Zombie'] > 0 | ||
&& pets['Lion-Skeleton'] > 0 | ||
&& pets['Lion-Base'] > 0 | ||
&& pets['Lion-Desert'] > 0 | ||
&& pets['Lion-Red'] > 0 | ||
&& pets['Lion-Shade'] > 0 | ||
&& pets['Lion-White']> 0 | ||
&& pets['Lion-Golden'] > 0 | ||
&& pets['Lion-CottonCandyBlue'] > 0 | ||
&& pets['Lion-CottonCandyPink'] > 0 | ||
&& pets['Tiger-Zombie'] > 0 | ||
&& pets['Tiger-Skeleton'] > 0 | ||
&& pets['Tiger-Base'] > 0 | ||
&& pets['Tiger-Desert'] > 0 | ||
&& pets['Tiger-Red'] > 0 | ||
&& pets['Tiger-Shade'] > 0 | ||
&& pets['Tiger-White'] > 0 | ||
&& pets['Tiger-Golden'] > 0 | ||
&& pets['Tiger-CottonCandyBlue'] > 0 | ||
&& pets['Tiger-CottonCandyPink'] > 0 | ||
&& pets['Sabretooth-Zombie'] > 0 | ||
&& pets['Sabretooth-Skeleton'] > 0 | ||
&& pets['Sabretooth-Base'] > 0 | ||
&& pets['Sabretooth-Desert'] > 0 | ||
&& pets['Sabretooth-Red'] > 0 | ||
&& pets['Sabretooth-Shade'] > 0 | ||
&& pets['Sabretooth-White'] > 0 | ||
&& pets['Sabretooth-Golden'] > 0 | ||
&& pets['Sabretooth-CottonCandyBlue'] > 0 | ||
&& pets['Sabretooth-CottonCandyPink'] > 0 | ||
&& pets['Cheetah-Zombie'] > 0 | ||
&& pets['Cheetah-Skeleton'] > 0 | ||
&& pets['Cheetah-Base'] > 0 | ||
&& pets['Cheetah-Desert'] > 0 | ||
&& pets['Cheetah-Red'] > 0 | ||
&& pets['Cheetah-Shade'] > 0 | ||
&& pets['Cheetah-White'] > 0 | ||
&& pets['Cheetah-Golden'] > 0 | ||
&& pets['Cheetah-CottonCandyBlue'] > 0 | ||
&& pets['Cheetah-CottonCandyPink'] > 0 ) { | ||
set['achievements.cats'] = true; | ||
|
||
} | ||
} | ||
|
||
if (count % progressCount === 0) console.warn(`${count} ${user._id}`); | ||
|
||
return await User.updateOne({ _id: user._id }, { $set: set }).exec(); | ||
} | ||
|
||
export default async function processUsers () { | ||
let query = { | ||
migration: { $ne: MIGRATION_NAME }, | ||
'auth.timestamps.loggedin': { $gt: new Date('2024-03-01') }, | ||
}; | ||
|
||
const fields = { | ||
_id: 1, | ||
items: 1, | ||
}; | ||
|
||
while (true) { // eslint-disable-line no-constant-condition | ||
const users = await User // eslint-disable-line no-await-in-loop | ||
.find(query) | ||
.limit(250) | ||
.sort({_id: 1}) | ||
.select(fields) | ||
.lean() | ||
.exec(); | ||
|
||
if (users.length === 0) { | ||
console.warn('All appropriate users found and modified.'); | ||
console.warn(`\n${count} users processed\n`); | ||
break; | ||
} else { | ||
query._id = { | ||
$gt: users[users.length - 1]._id, | ||
}; | ||
} | ||
|
||
await Promise.all(users.map(updateUser)); // eslint-disable-line no-await-in-loop | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters