Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses performance issues with course rating statistics by implementing per-tenant caching and refactoring the API to support single-tenant queries. The changes shift from computing ratings across all accessible tenants to computing and caching results for one tenant at a time, significantly improving response times for the ratings endpoint.
Key Changes
- Refactored
get_courses_ratingsto accepttenant_idparameter instead offx_permission_info, with results cached per tenant using thecache_dictdecorator - Modified
GlobalRatingViewto require exactly one tenant ID via query parameter, with validation to ensure users only access authorized tenants - Added
FX_CACHE_TIMEOUT_COURSES_RATINGSsetting (default 15 minutes) to control cache expiration for rating statistics
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| futurex_openedx_extensions/dashboard/statistics/courses.py | Refactored get_courses_ratings to use tenant_id parameter and added caching with cache key generation; introduced RATING_RANGE constant |
| futurex_openedx_extensions/dashboard/views.py | Updated GlobalRatingView to enforce single-tenant queries with validation and authorization checks; added RATING_RANGE constant and improved error handling |
| futurex_openedx_extensions/dashboard/settings/common_production.py | Added FX_CACHE_TIMEOUT_COURSES_RATINGS configuration setting |
| test_utils/test_settings_common.py | Added FX_CACHE_TIMEOUT_COURSES_RATINGS test configuration |
| tests/test_dashboard/test_statistics/test_courses.py | Updated tests to use new tenant_id parameter signature |
| tests/test_dashboard/test_views.py | Enhanced tests to cover new single-tenant requirement, parameter validation, and error cases; added PermissionDenied import |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ant ID and improve error handling
…cess control error responses
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9ed124f to
bf92300
Compare
This pull request refactors the course ratings API to support per-tenant queries and introduces caching for course ratings results. The changes improve performance by caching results per tenant, enforce stricter API input validation, and update related tests and settings to support the new behavior.
API and Business Logic Changes
get_courses_ratingsfunction now takes atenant_idargument instead of permission info, computes ratings for a single tenant, and caches results per tenant using a generated cache key and a configurable timeout (FX_CACHE_TIMEOUT_COURSES_RATINGS). [1] [2] [3]GlobalRatingViewAPI endpoint now requires exactly one tenant ID via thetenant_idsquery parameter, validates access, and returns ratings only for the specified tenant. It raises appropriate exceptions for missing, multiple, invalid, or unauthorized tenant IDs.Settings and Constants
FX_CACHE_TIMEOUT_COURSES_RATINGS(default 15 minutes) to both production and test settings, controlling the cache timeout for course ratings per tenant. [1] [2]RATING_RANGE = range(1, 6)for rating calculations and response formatting. [1] [2]Testing Updates
Imports and Minor Refactoring
References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]