Skip to content
Snippets Groups Projects
Unverified Commit 2a008fac authored by Eric Fischer's avatar Eric Fischer Committed by GitHub
Browse files

Merge pull request #18121 from edx/efischer/one_more_time

Cache results of thread authorship check
parents 225dc102 efd9fc04
No related merge requests found
......@@ -65,11 +65,27 @@ def _check_condition(user, condition, content):
if not content:
return False
try:
request_cache_dict = RequestCache.get_request_cache().data
if content["type"] == "thread":
return content["thread_type"] == "question" and content["user_id"] == str(user.id)
cache_key = "django_comment_client.permissions._check_condition.check_question_author.{}.{}".format(
user.id, content['id']
)
if cache_key in request_cache_dict:
return request_cache_dict[cache_key]
else:
result = content["thread_type"] == "question" and content["user_id"] == str(user.id)
request_cache_dict[cache_key] = result
return result
else:
# N.B. This will trigger a comments service query
return check_question_author(user, Thread(id=content["thread_id"]).to_dict())
cache_key = "django_comment_client.permissions._check_condition.check_question_author.{}.{}".format(
user.id, content['thread_id']
)
if cache_key in request_cache_dict:
return request_cache_dict[cache_key]
else:
# make the now-unavoidable comments service query
thread = Thread(id=content['thread_id']).to_dict()
return check_question_author(user, thread)
except KeyError:
return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment