mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
perf(groups): use simplest possible query for cron script (#15457)
This commit is contained in:
@@ -8,7 +8,16 @@ const TASK_VALUE_CHANGE_FACTOR = 0.9747;
|
|||||||
const MIN_TASK_VALUE = -47.27;
|
const MIN_TASK_VALUE = -47.27;
|
||||||
|
|
||||||
async function updateTeamTasks (team) {
|
async function updateTeamTasks (team) {
|
||||||
|
if (team.purchased.plan.dateTerminated) {
|
||||||
|
const dateTerminated = new Date(team.purchased.plan.dateTerminated);
|
||||||
|
if (dateTerminated < new Date()) {
|
||||||
|
team.purchased.plan.customerId = undefined;
|
||||||
|
return team.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const toSave = [];
|
const toSave = [];
|
||||||
|
|
||||||
let teamLeader = await User.findOne({ _id: team.leader }, 'preferences').exec();
|
let teamLeader = await User.findOne({ _id: team.leader }, 'preferences').exec();
|
||||||
|
|
||||||
if (!teamLeader) { // why would this happen?
|
if (!teamLeader) { // why would this happen?
|
||||||
@@ -93,12 +102,7 @@ async function updateTeamTasks (team) {
|
|||||||
export default async function processTeamsCron () {
|
export default async function processTeamsCron () {
|
||||||
const activeTeams = await Group.find({
|
const activeTeams = await Group.find({
|
||||||
'purchased.plan.customerId': { $exists: true },
|
'purchased.plan.customerId': { $exists: true },
|
||||||
$or: [
|
}, { cron: 1, leader: 1, purchased: 1 }).exec();
|
||||||
{ 'purchased.plan.dateTerminated': { $exists: false } },
|
|
||||||
{ 'purchased.plan.dateTerminated': null },
|
|
||||||
{ 'purchased.plan.dateTerminated': { $gt: new Date() } },
|
|
||||||
],
|
|
||||||
}).exec();
|
|
||||||
|
|
||||||
const cronPromises = activeTeams.map(updateTeamTasks);
|
const cronPromises = activeTeams.map(updateTeamTasks);
|
||||||
return Promise.all(cronPromises);
|
return Promise.all(cronPromises);
|
||||||
|
|||||||
Reference in New Issue
Block a user