mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Optimize database access for some use cases (#15444)
* optimize query when listing challenge tasks * Optimize query for checking if user is party leader
This commit is contained in:
@@ -1316,13 +1316,13 @@ api.getLookingForParty = {
|
||||
const PAGE = req.query.page || 0;
|
||||
const PAGE_START = USERS_PER_PAGE * PAGE;
|
||||
|
||||
const partyLed = await Group
|
||||
.findOne({
|
||||
type: 'party',
|
||||
leader: user._id,
|
||||
})
|
||||
.select('_id')
|
||||
.exec();
|
||||
let partyLed = false;
|
||||
if (user.party._id) {
|
||||
const party = await Group.getGroup({ user, groupId: user.party._id });
|
||||
if (party && party.leader === user._id) {
|
||||
partyLed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!partyLed) {
|
||||
throw new BadRequest(apiError('notPartyLeader'));
|
||||
|
||||
Reference in New Issue
Block a user