Skip to content

Use simplest possible query for cron script #15457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged

Conversation

SabreCat
Copy link
Member

Before, the Group Plan scheduled script performed a MongoDB query filtering on both the existence of purchased.plan.customerId and an $or between several possible states of purchased.plan.dateTerminated that were valid for an active subscription. This operation was not performant, leading to a high number of scanned document keys and ultimately queries taking ten seconds or more to complete.

Now, we perform the minimal query for existence of purchased.plan.customerId, which should be quick to resolve using a sparse index. Then within the script, after retrieving each group, we check whether its purchased.plan.dateTerminated indicates an expired sub. If so, we clear out the purchased.plan.customerId and move on to the next, so we can rely on the main query to exclude that group in future runs.

Copy link
Member

@phillipthelen phillipthelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@SabreCat SabreCat merged commit f8a3e4d into develop Jun 25, 2025
10 checks passed
@SabreCat SabreCat deleted the kalista/group-cron-perf branch June 25, 2025 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants