mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00: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:
parent
972f23e235
commit
5ba7d2395e
2 changed files with 8 additions and 8 deletions
|
|
@ -1316,13 +1316,13 @@ api.getLookingForParty = {
|
||||||
const PAGE = req.query.page || 0;
|
const PAGE = req.query.page || 0;
|
||||||
const PAGE_START = USERS_PER_PAGE * PAGE;
|
const PAGE_START = USERS_PER_PAGE * PAGE;
|
||||||
|
|
||||||
const partyLed = await Group
|
let partyLed = false;
|
||||||
.findOne({
|
if (user.party._id) {
|
||||||
type: 'party',
|
const party = await Group.getGroup({ user, groupId: user.party._id });
|
||||||
leader: user._id,
|
if (party && party.leader === user._id) {
|
||||||
})
|
partyLed = true;
|
||||||
.select('_id')
|
}
|
||||||
.exec();
|
}
|
||||||
|
|
||||||
if (!partyLed) {
|
if (!partyLed) {
|
||||||
throw new BadRequest(apiError('notPartyLeader'));
|
throw new BadRequest(apiError('notPartyLeader'));
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,7 @@ async function getTasks (req, res, options = {}) {
|
||||||
} else {
|
} else {
|
||||||
query.type = type.slice(0, -1); // removing the final "s"
|
query.type = type.slice(0, -1); // removing the final "s"
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!challenge) {
|
||||||
query.$and = [{
|
query.$and = [{
|
||||||
$or: [ // Exclude completed todos
|
$or: [ // Exclude completed todos
|
||||||
{ type: 'todo', completed: false },
|
{ type: 'todo', completed: false },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue