Optimise looking for party request (#14773)

* Reset looking for party state if a user joins a party

* filter out users that already received an invite in query

* fix(lfp): add back in-party filter
Temporary until migration to clear seeking flag from users in party

---------

Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
Phillip Thelen
2023-07-25 21:16:03 +02:00
committed by GitHub
parent 683649ff1a
commit 754d46f1f3

View File

@@ -590,9 +590,10 @@ api.joinGroup = {
if (userPreviousParty) await userPreviousParty.leave(user);
}
}
// Clear all invitations of new user
// Clear all invitations of new user and reset looking for party state
user.invitations.parties = [];
user.invitations.party = {};
user.party.seeking = null;
// invite new user to pending quest
if (group.quest.key && !group.quest.active) {
@@ -1393,6 +1394,7 @@ api.getLookingForParty = {
const seekers = await User
.find({
'party.seeking': { $exists: true },
'invitations.party.id': { $exists: false },
'auth.timestamps.loggedin': {
$gt: moment().subtract(7, 'days').toDate(),
},
@@ -1408,7 +1410,6 @@ api.getLookingForParty = {
const filteredSeekers = seekers.filter(seeker => {
if (seeker.party._id) return false;
if (seeker.invitations.party.id) return false;
if (seeker.flags.chatRevoked) return false;
if (seeker.auth.blocked) return false;
if (seeker.inbox.blocks.indexOf(user._id) !== -1) return false;