Remove updateChallengeCompletionMetrics scheduled job#1246
Merged
Conversation
|
Contributor
|
LGTM, i tested locally and things work well in both frontends. Will keep the problems you noted in mind. |
CollinBeczak
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



#1236 added a new
completion_metricsJSONB column which is kept up to date by triggers, but it did not remove the scheduled job that maintains the oldcompletion_percentageandtasks_remainingcounts. Having both at once creates write contention on the challenges and projects tables and makes lots of API operations very slow while the job is running.This PR does the following:
completion_percentageandtasks_remainingcolumns (and computes those fields from thecompletion_metricsdata when building JSON responses)updateCompletionMetricsOfActiveChallengesjob which maintained those columnsupdate_challenge_completion_metricsandupdate_project_completion_metricsSQL functions are triggered, so updating a task (or challenge) will only recompute metrics for the parent challenge (or project) if a column was modified that could affect the results.There are still problems with the present approach which we should fix in a future PR:
INSERTorUPDATEthem in individual queries. This is an antipattern on its own (refreshing a challenge with 50k tasks means 50k DB roundtrips), but it also means that even if we switch to per-statement triggers as described above, we still won't see any benefit until these code paths are refactored to insert/update tasks in batches.