Uh oh!
There was an error while loading. Please reload this page.
Optimize admin page performance with lazy loading and limit sessions query to last 5 classes#1524
Conversation
Co-authored-by: karbassi <17738+karbassi@users.noreply.github.com>
Co-authored-by: karbassi <17738+karbassi@users.noreply.github.com>
karbassi
commented
Sep 12, 2025
I still want a way to view more classes, up to all the classes in the last 365 days, but I don’t want them initially fetched on page load. |
Co-authored-by: karbassi <17738+karbassi@users.noreply.github.com>
I've implemented a "Load More Classes" button that allows viewing additional sessions up to all classes from the last 365 days without initially fetching them on page load. Implementation details:
The performance optimization is maintained - only the initial 5 sessions are loaded on page load, with additional sessions fetched on demand. This provides the best of both worlds: fast initial load times and the ability to view more historical data when needed. Commit: 6699198 |
Co-authored-by: karbassi <17738+karbassi@users.noreply.github.com>
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.