Skip to content

Count is inaccurate for large numbers of enrollments #3073

@brianhogg

Description

@brianhogg

Reproduction Steps

  1. View the enrollment count for a course under LifterLMS > Reporting > Courses, and selecting a course (number above "Currently enrolled students")
  2. View the enrollment count for a course by going to LifterLMS > Reporting > Enrollments, and filter by the same course. Set the date range to cover all the time the course was opened.

Expected Behavior

Numbers match, if there have not been any unenrollments.

Actual Behavior

Numbers do not match and are rounded

Tech Notes

We are using the now deprecated SQL_CALC_FOUND_ROWS to do the calculation with a low LIMIT clause, for the course overview query, via LLMS_Student_Query. With the Enrollments widget we are doing a custom query and a PHP count() on all the results.

Instead we should do a query with SELECT COUNT(*) in these three locations and get the count that way:

  • LLMS_Course::get_student_count
  • LLMS_Analytics_Enrollments_Widget::set_query waiting on this since it's a per-day count calculated on the front-end.
  • LLMS_Processor_Course_Data::dispatch_calc

We could possibly add a count_only or similar param to our abstract query, but it would need to handle certain queries like the student query adding the status as an extra SELECT sub-query:

SELECT SQL_CALC_FOUND_ROWS u.ID as id, ( SELECT meta_value
				FROM wp_lifterlms_user_postmeta
				WHERE meta_key = '_status'
		  		  AND user_id = id
		  		  AND post_id IN ( ... )
				ORDER BY updated_date DESC
				LIMIT 1 ) AS status
			FROM wp_users AS u
			
			
			HAVING status IS NOT NULL AND status IN ( 'enrolled' )
			ORDER BY id ASC
;

HS-268782

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions