Skip to content

Commit

Permalink
YONK-1219 - Code optimization for more performance (#216)
Browse files Browse the repository at this point in the history
* Code modified to fetch Tips only once for every MRQ problem
* student_view_data API optimized to fetch tips only if hide_results is set to False
  • Loading branch information
shafqatfarhan authored and xitij2000 committed Nov 23, 2018
1 parent 530b867 commit 0e45350
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions problem_builder/mrq.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def submit(self, submissions):
def calculate_results(self, submissions):
score = 0
results = []
tips = None

if not self.hide_results:
tips = self.get_tips()

for choice in self.custom_choices:
choice_completed = True
Expand All @@ -131,9 +135,6 @@ def calculate_results(self, submissions):
choice_completed = False
elif choice_selected and choice.value not in self.ignored_choices:
choice_completed = False
for tip in self.get_tips():
if choice.value in tip.values:
choice_tips_html.append(self.expand_static_url(tip.render('mentoring_view').content))

if choice_completed:
score += 1
Expand All @@ -145,6 +146,13 @@ def calculate_results(self, submissions):
}
# Only include tips/results in returned response if we want to display them
if not self.hide_results:
# choice_tips_html list is being set only when 'self.hide_results' is False, to optimize,
# execute the loop only when 'self.hide_results' is set to False
for tip in tips:
if choice.value in tip.values:
choice_tips_html.append(self.expand_static_url(tip.render('mentoring_view').content))
break

loader = ResourceLoader(__name__)
choice_result['completed'] = choice_completed
choice_result['tips'] = loader.render_template('templates/html/tip_choice_group.html', {
Expand Down Expand Up @@ -218,5 +226,6 @@ def student_view_data(self, context=None):
for choice in self.human_readable_choices
],
'hide_results': self.hide_results,
'tips': [tip.student_view_data() for tip in self.get_tips()],
'tips': [tip.student_view_data() for tip in
self.get_tips()] if not self.hide_results else [],
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def package_data(pkg, root_list):

setup(
name='xblock-problem-builder',
version='2.11.2',
version='2.11.3',
description='XBlock - Problem Builder',
packages=find_packages(),
install_requires=[
Expand Down

0 comments on commit 0e45350

Please sign in to comment.