Fix community XP ranking and sync consistency#920
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughCommunity social-task completions now contribute to effective community scores, leaderboard and dashboard totals, participant growth metrics, and earned-role qualification. MEE6 synchronization validates social-task distributions and shares lock ownership across fetch, apply, and Discord XP mutations. ChangesSocial-task scoring and synchronization
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant SocialTaskCompletion
participant EffectiveCommunityScores
participant LeaderboardViewSet
User->>SocialTaskCompletion: complete community task
SocialTaskCompletion->>EffectiveCommunityScores: contribute awarded points
EffectiveCommunityScores->>LeaderboardViewSet: provide effective totals
LeaderboardViewSet->>User: return leaderboard and profile totals
sequenceDiagram
participant SyncRequest
participant SyncLock
participant Mee6Sync
participant DiscordXPState
SyncRequest->>SyncLock: acquire owner token
SyncRequest->>Mee6Sync: fetch and apply snapshot
Mee6Sync->>SyncLock: refresh and validate ownership
DiscordXPState->>SyncLock: request mutation lock
SyncLock-->>DiscordXPState: return conflict during sync
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/contributions/views.py (1)
1866-1919: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
record_copyholds the MEE6 sync lock during an uncapped Discord request.
refresh_connection_username()makes synchronous Discord calls without an explicit timeout, so a slow or hung response can keep the global lock occupied until the stale-lock window (default 3600s) and block other syncs. Since this path only updateslast_copied_at/last_copied_by, scope the lock to the actual XP mutation or add a bounded timeout around the Discord refresh.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/contributions/views.py` around lines 1866 - 1919, Update record_copy so the global lock acquired by _acquire_xp_mutation_lock is not held while _refresh_discord_connection performs synchronous Discord requests. Move lock acquisition to immediately before the last_copied_at/last_copied_by mutation, or enforce a bounded timeout for the refresh, while preserving the existing atomic update and release behavior.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@backend/contributions/views.py`:
- Around line 1866-1919: Update record_copy so the global lock acquired by
_acquire_xp_mutation_lock is not held while _refresh_discord_connection performs
synchronous Discord requests. Move lock acquisition to immediately before the
last_copied_at/last_copied_by mutation, or enforce a bounded timeout for the
refresh, while preserving the existing atomic update and release behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 60df5f3c-6f70-4903-99c3-de0ebea9d447
📒 Files selected for processing (13)
backend/CLAUDE.mdbackend/api/metrics_views.pybackend/api/tests.pybackend/community_xp/services.pybackend/community_xp/tests/test_mee6_sync.pybackend/community_xp/utils.pybackend/community_xp/views.pybackend/contributions/tests/test_discord_xp.pybackend/contributions/views.pybackend/leaderboard/tests/test_stats.pybackend/leaderboard/views.pybackend/social_connections/tests/test_earned_roles.pybackend/social_tasks/tests/test_leaderboard_integration.py
Summary
Summary by CodeRabbit