Skip to content

Fix reports screen times out on larger sites#7859

Merged
m1r0 merged 3 commits intotrunkfrom
fix/slow-query-on-reports-screen
Oct 28, 2025
Merged

Fix reports screen times out on larger sites#7859
m1r0 merged 3 commits intotrunkfrom
fix/slow-query-on-reports-screen

Conversation

@m1r0
Copy link
Member

@m1r0 m1r0 commented Oct 27, 2025

Resolves #7857
Resolves SEN-23
Probably resolves #4962
Relates to #7858

Proposed Changes

  • The PR fixes a slow query on the reports screen that causes a timeout on bigger sites. The performance increase is more than 10-fold.

Testing Instructions

  1. Have the Query Monitor plugin installed.
  2. Go to Sensei LMS > Reports
  3. Look for the query in the screenshot below and compare it trunk.
  4. Make sure the listed users and last activity dates are still the same as in trunk
  5. Make sure the "Last Activity" date filter still works as before.
  6. Make sure the "Last Activity" table sorting still works as before.
  7. Make sure the "Export all rows" still works as before.
Before After
image image

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • Code is tested on the minimum supported PHP and WordPress versions

@m1r0 m1r0 self-assigned this Oct 27, 2025
@m1r0 m1r0 added this to the 4.25.2 milestone Oct 27, 2025
@m1r0 m1r0 marked this pull request as ready for review October 27, 2025 12:51
Copilot AI review requested due to automatic review settings October 27, 2025 12:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes a slow query on the Sensei LMS reports screen that was causing timeouts on larger sites. The optimization converts a correlated subquery into a LEFT JOIN with GROUP BY, which significantly improves query performance by eliminating the need to execute the subquery for each user row.

Key Changes:

  • Replaced a correlated subquery with a LEFT JOIN to fetch last activity dates more efficiently
  • Removed the USE INDEX hint that is no longer needed with the new query structure

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
includes/reports/overview/data-provider/class-sensei-reports-overview-data-provider-students.php Refactored the SQL query to use LEFT JOIN instead of a correlated subquery for better performance
changelog/fix-slow-query-on-reports-screen Added changelog entry documenting the query optimization fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@m1r0
Copy link
Member Author

m1r0 commented Oct 27, 2025

@donnapep, if you have the opportunity, could you please give this one a look? 🙏

@m1r0 m1r0 changed the title Optimize a slow query on the reports screen Fix reports screen times out on larger sites Oct 28, 2025
@m1r0
Copy link
Member Author

m1r0 commented Oct 28, 2025

It was confirmed that this is fixed. 🚀

@m1r0 m1r0 merged commit 8595160 into trunk Oct 28, 2025
17 checks passed
@m1r0 m1r0 deleted the fix/slow-query-on-reports-screen branch October 28, 2025 12:09
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.

Sensei Reports page times out on large sites One query running for all the pages and making many them load slow for large data

2 participants