Skip to content

Cache leaderboard data to improve page load performance#148

Merged
alexeygrigorev merged 4 commits into
mainfrom
copilot/optimize-leaderboard-loading-time
Jan 30, 2026
Merged

Cache leaderboard data to improve page load performance#148
alexeygrigorev merged 4 commits into
mainfrom
copilot/optimize-leaderboard-loading-time

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 29, 2026

Leaderboard pages experienced slow loading due to repeated database queries fetching all course enrollments on each request.

Changes

Cache configuration

  • Added LocMemCache backend in Django settings for in-memory caching

Leaderboard view (courses/views/course.py)

  • Cache enrollment data as dictionaries (not model instances to avoid stale field values)
  • Cache key: leaderboard:{course_id}, TTL: 1 hour
  • Example:
cache_key = f"leaderboard:{course.id}"
enrollments_data = cache.get(cache_key)

if enrollments_data is None:
    enrollments = Enrollment.objects.filter(course=course).select_related('student').order_by(...)
    enrollments_data = [
        {'id': e.id, 'display_name': e.display_name, 'total_score': e.total_score, ...}
        for e in enrollments
    ]
    cache.set(cache_key, enrollments_data, 3600)

Cache invalidation (courses/scoring.py)

  • update_leaderboard() deletes cache after bulk updating enrollment scores
  • Triggered automatically on homework/project scoring completion

Test updates

  • Added cache invalidation test
  • Clear cache in test setUp to prevent cross-test pollution
  • Updated assertions to work with dictionary data

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Page slow loading time</issue_title>
<issue_description>Some pages show very slow loading time, especially leaderboard.

For leaderboard let's cache it and invalidate the cache when some important events happen (leaderboard recalculation)

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 29, 2026 19:23
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
…tances

Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Copilot AI changed the title [WIP] Add caching mechanism for leaderboard to improve loading speed Cache leaderboard data to improve page load performance Jan 29, 2026
Copilot AI requested a review from alexeygrigorev January 29, 2026 19:39
@alexeygrigorev alexeygrigorev marked this pull request as ready for review January 29, 2026 20:40
@alexeygrigorev alexeygrigorev merged commit 83330d7 into main Jan 30, 2026
2 checks passed
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.

Page slow loading time

2 participants