Optimize admin page performance with lazy loading and limit sessions query to last 5 classes #1524
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR optimizes the admin page load times by limiting the database query to retrieve only the last 5 sessions initially, and adds on-demand loading functionality to view additional sessions up to the last 365 days.
Problem
The admin page was retrieving ALL sessions from the database and using client-side CSS collapse to hide sessions beyond the first 5. This approach:
Solution
Modified the sessions queryset to use database-level limiting with
[:5]slice and added AJAX-based "Load More" functionality:Before:
After:
New Load More Functionality:
/admin/load-more-sessions/AJAX endpoint that loads 10 sessions at a timeAlso cleaned up the template by removing the now-unnecessary collapse functionality:
session-collapseCSS classes from table rowsBenefits
User Experience
Admins see the last 5 classes on initial page load for optimal performance. When more sessions are available within the last 365 days, a "Load More Classes" button allows viewing additional sessions without page reload. The optimization maintains fast initial load times while providing access to historical data when needed.
Testing
Added comprehensive test suite in
test_admin_load_more_sessions.pycovering:Fixes #877.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.