Skip to content

Commit

Permalink
Merge pull request #458 from openedx/cag/cache-objects
Browse files Browse the repository at this point in the history
perf: add lru cache for users and courses
  • Loading branch information
Ian2012 authored Oct 15, 2024
2 parents 42c9e8e + bfedbbc commit ba1c882
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions event_routing_backends/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import logging
import uuid
from functools import lru_cache
from urllib.parse import parse_qs, urlparse

from dateutil.parser import parse
Expand Down Expand Up @@ -52,6 +53,7 @@ def get_uuid5(namespace_key, name):
return uuid.uuid5(base_namespace, name)


@lru_cache
def get_anonymous_user_id(username_or_id, external_type):
"""
Generate anonymous user id.
Expand Down Expand Up @@ -150,6 +152,7 @@ def get_user_email(username_or_id):
return user_email


@lru_cache
def get_course_from_id(course_id):
"""
Get Course object using the `course_id`.
Expand Down
2 changes: 1 addition & 1 deletion event_routing_backends/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_get_anonymous_user_id_with_error(self, mocked_external_id):
mocked_external_id.add_new_user_id.return_value = (None, False)
# Test that a failure to add an external id raises an error
with self.assertRaises(ValueError):
get_anonymous_user_id('edx', 'XAPI')
get_anonymous_user_id('edx2', 'XAPI')

# Test that an unknown user raises this error
with self.assertRaises(ValueError):
Expand Down

0 comments on commit ba1c882

Please sign in to comment.