Skip to content

fix: Activity count not incremented for anonymous posts in Learners tab#54

Open
rahulkanneri-2u wants to merge 2 commits into
edx:release-ulmofrom
rahulkanneri-2u:cosmo2-895-activity-count-issue-for-anonymous-users
Open

fix: Activity count not incremented for anonymous posts in Learners tab#54
rahulkanneri-2u wants to merge 2 commits into
edx:release-ulmofrom
rahulkanneri-2u:cosmo2-895-activity-count-issue-for-anonymous-users

Conversation

@rahulkanneri-2u
Copy link
Copy Markdown

@rahulkanneri-2u rahulkanneri-2u commented May 28, 2026

Description

The existing stats logic was inconsistently excluding anonymous threads and comments from course stats depending on the backend. For MySQL, anonymous posts were being filtered out from build_course_stats, update_all_users_in_course, and restore_thread/restore_comment operations. For MongoDB, the exclusion only happened in create_thread and delete_thread. This PR aligns both backends: MySQL now counts anonymous posts in all stat operations (matching the intended behaviour), while MongoDB continues to exclude anonymous posts only in create_thread and delete_thread. The e2e test assertion is also corrected to reflect the per-backend expected counts.

Changes Included

  • forum/api/threads.py — Updated create_thread() and delete_thread() guards to skip stat updates only for MongoDB + anonymous posts; MySQL now always updates stats regardless of anonymity.
  • forum/backends/mysql/api.py — Removed anonymous=False / anonymous_to_peers=False filters from build_course_stats() and update_all_users_in_course() queries; removed the is_anonymous guard from restore_comment() and restore_thread() so restoring anonymous content correctly reverses its stats.
  • tests/e2e/test_users.py — Fixed test_build_course_stats_with_anonymous_posts assertion to expect 1 thread for MongoDB and 3 for MySQL, and updated the docstring to reflect actual intent.
  • tests/test_backends/test_mysql/test_api.py — Added four new unit tests covering: counting anonymous threads, counting anonymous-to-peers threads in build_course_stats, and stats updates on restore_thread / restore_comment for anonymous content.

Tickets

@rahulkanneri-2u rahulkanneri-2u force-pushed the cosmo2-895-activity-count-issue-for-anonymous-users branch from 0241924 to ec9f803 Compare May 29, 2026 10:21
@rahulkanneri-2u rahulkanneri-2u force-pushed the cosmo2-895-activity-count-issue-for-anonymous-users branch from d1b866c to 0b2f53a Compare May 29, 2026 10:22
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