Skip to content

Restrict moodle:sync bulk pass to recently-active users - #117

Merged
Celeo merged 1 commit into
masterfrom
moodle-sync-active-users-filter
Jul 27, 2026
Merged

Restrict moodle:sync bulk pass to recently-active users#117
Celeo merged 1 commit into
masterfrom
moodle-sync-active-users-filter

Conversation

@Celeo

@Celeo Celeo commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • moodle:sync's bulk pass (app/Console/Commands/MoodleSync.php) scans and diffs the entire users table (25,000+ rows) every 3 hours with no activity filter, contributing to the Moodle mdl_course.cacherev lock 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.
  • Adds a lastactivity >= now()-90d filter to the bulk query. lastactivity is kept current by current's AuthLastActivity middleware on every authenticated page load, so this reliably reflects real usage.
  • This is a companion to a cobalt PR that adds a login-time Moodle cohort sync, replacing the dead api ULSHelper::doHandleLogin trigger 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)
  • Run php artisan moodle:sync on staging and confirm the "starting bulk pass" log line reports a reduced user count vs. before
  • Confirm a manually-triggered single-user sync (php artisan moodle:sync {cid}) is unaffected, since the filter only applies to the bulk path
  • Monitor api-worker logs for a full scheduled run to confirm reduced cacherev contention

🤖 Generated with Claude Code

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>
@Celeo
Celeo merged commit 61bf0c5 into master Jul 27, 2026
3 checks passed
@Celeo
Celeo deleted the moodle-sync-active-users-filter branch July 27, 2026 20:20
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.

1 participant