Restrict moodle:sync bulk pass to recently-active users - #117
Merged
Conversation
The bulk pass scans the entire users table every 3 hours with no activity filter, driving Moodle's cohort/role writes hard enough to trigger cacherev lock contention (see PRs #114/#115's diff-based rewrite, which cut write volume but didn't bound the scan itself). Users who haven't logged in in months have no pending facility/rating/ staff-role changes to reconcile, so there's no reason to keep including them as the table keeps growing. New-controller Observer cohort onboarding no longer depends on this job at all -- that's now handled at login time in cobalt (see companion cobalt PR) -- so narrowing this job's scope doesn't affect onboarding latency, only reduces backstop maintenance-sync volume. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
moodle:sync's bulk pass (app/Console/Commands/MoodleSync.php) scans and diffs the entireuserstable (25,000+ rows) every 3 hours with no activity filter, contributing to the Moodlemdl_course.cacherevlock contention documented in the moodle-sync investigation, on top of the diff-based write reduction already shipped in Diff moodle:sync cohort membership instead of clearing and re-inserting every run #114/Diff moodle:sync role assignments instead of clearing and reassigning every run #115.lastactivity >= now()-90dfilter to the bulk query.lastactivityis kept current bycurrent'sAuthLastActivitymiddleware on every authenticated page load, so this reliably reflects real usage.apiULSHelper::doHandleLogintrigger as the source of truth for new-controller Observer cohort onboarding. This bulk job becomes a pure maintenance backstop (facility/rating/staff-role changes outside a fresh login) rather than the last line of defense for onboarding, so scoping it down doesn't affect new-controller latency.Test plan
php -l app/Console/Commands/MoodleSync.php(done, clean)php artisan moodle:syncon staging and confirm the "starting bulk pass" log line reports a reduced user count vs. beforephp artisan moodle:sync {cid}) is unaffected, since the filter only applies to the bulk pathapi-workerlogs for a full scheduled run to confirm reduced cacherev contention🤖 Generated with Claude Code