Optimizes report queries and improves session pairing logic#172
Merged
Conversation
Refactors report generation to reduce database queries by batching and bucketizing event data in Python, significantly improving performance for time-based aggregations. Updates session calculation to use SQL window functions for accurate LOGIN/LOGOUT pairing, ensuring correctness even with out-of-order events. Standardizes time zone handling and interval validation for consistency across reports.
dkmstr
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 pull request introduces several optimizations and correctness improvements to the statistics and reporting modules, focusing on more efficient data aggregation, improved database query patterns, and better handling of time zones. The changes reduce the number of queries (eliminating N+1 issues), leverage database window functions for accurate event pairing, and ensure consistent and correct time handling in reports.
Database Query Optimization and Event Pairing:
pools_performance.pyanduser_access.py, significantly improving performance and scalability. [1] [2]Lagover partitions) for accurate LOGIN/LOGOUT event pairing inpool_users_summary.pyandusage_by_pool.py, ensuring "last login wins" semantics and eliminating manual event grouping in Python. [1] [2]Time Zone Handling and Date Formatting:
timezone.make_aware, preventing issues with naive datetimes in reports and charts. [1] [2] [3] [4] [5]Code Simplification and Correctness:
pools_performance.pyanduser_access.py. [1] [2]Data Model and API Improvements:
pools_performance.pyandusage_by_pool.py. [1] [2]Other Minor Improvements:
usage_by_pool.py.These changes collectively improve the accuracy, efficiency, and maintainability of the reporting features.
DEV Explain
As we did in version 5.0, we are backporting here the optimizations to report queries and the improvement to the session matching logic.