Commit 41dfa3e5 by Calen Pennington

Cache anonymous user id on the user object, so that queries aren't made many…

Cache anonymous user id on the user object, so that queries aren't made many times over during module rendering
parent 560347d0
......@@ -66,6 +66,10 @@ def anonymous_id_for_user(user, course_id):
if user.is_anonymous():
return None
cached_id = getattr(user, '_anonymous_id', {}).get(course_id)
if cached_id is not None:
return cached_id
# include the secret key as a salt, and to make the ids unique across different LMS installs.
hasher = hashlib.md5()
hasher.update(settings.SECRET_KEY)
......@@ -94,6 +98,11 @@ def anonymous_id_for_user(user, course_id):
# continue
pass
if not hasattr(user, '_anonymous_id'):
user._anonymous_id = {}
user._anonymous_id[course_id] = digest
return digest
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment