Skip to content

Commit

Permalink
fix: optimized validUserId lookup on API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Nov 11, 2024
1 parent d7b1d98 commit d54e362
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions app/controllers/api/v1/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,30 @@ async function lookup(ctx) {
if (domain.is_global) {
// TODO: implement caching here
// TODO: maxTimeMS: 30000
const validUserIds = await Users.distinct('id', {
$or: [
// get all paid users with expiration is >= 30 days ago
{
plan: { $in: ['enhanced_protection', 'team'] },
[config.userFields.planExpiresAt]: {
$gte: dayjs().subtract(30, 'days').toDate()
}
},
// get all admin users
{
group: 'admin'
const arr = await Users.aggregate([
{
$match: {
$or: [
// get all paid users with expiration is >= 30 days ago
{
plan: { $in: ['enhanced_protection', 'team'] },
[config.userFields.planExpiresAt]: {
$gte: dayjs().subtract(30, 'days').toDate()
}
},
// get all admin users
{
group: 'admin'
}
]
}
]
});
},
{ $group: { _id: '$id' } }
])
.allowDiskUse(true)
.exec();

const validUserIdSet = new Set(validUserIds);
const validUserIdSet = new Set(arr.map((v) => v._id));

aliases = aliases.filter((a) => {
return (
Expand Down

0 comments on commit d54e362

Please sign in to comment.