From dc8dd51d1eb5f0131862e4433d4cc91964cee730 Mon Sep 17 00:00:00 2001 From: Franco Bulgarelli Date: Sat, 23 Jan 2021 22:18:57 -0300 Subject: [PATCH 01/13] 1st optimization: preload lesson's exercises --- app/views/chapters/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/chapters/show.html.erb b/app/views/chapters/show.html.erb index d8ab2bf487..1fe8be2073 100644 --- a/app/views/chapters/show.html.erb +++ b/app/views/chapters/show.html.erb @@ -26,7 +26,7 @@

<%= t(:lessons) %>

- <% @chapter.lessons.each do |lesson| %> + <% @chapter.lessons.includes(guide: :exercises).each do |lesson| %>

<%= lesson.number %>. <%= link_to_path_element lesson, mode: :plain %>

<%= render partial: 'layouts/progress_listing', locals: { exercises: lesson.exercises } %> <% end %> From c66abf816e9394530986bd21a2bc31676bc6ce12 Mon Sep 17 00:00:00 2001 From: Franco Leonardo Bulgarelli Date: Tue, 26 Jan 2021 13:59:19 -0300 Subject: [PATCH 02/13] Point to domain branch --- Gemfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 7e379383cc..f38fc0840b 100644 --- a/Gemfile +++ b/Gemfile @@ -40,3 +40,6 @@ group :development, :test do gem 'teaspoon-jasmine' gem 'selenium-webdriver' end + + +gem "mumuki-domain", github: "mumuki/mumuki-domain", branch: "chore-database-optimization" \ No newline at end of file From 04c15142449c619e408c2d183788d95acf0e37f6 Mon Sep 17 00:00:00 2001 From: Franco Bulgarelli Date: Sat, 23 Jan 2021 22:19:40 -0300 Subject: [PATCH 03/13] 2nd optimization: Use assignments_for & reuse them --- app/helpers/icons_helper.rb | 10 +++------- app/views/chapters/show.html.erb | 2 +- app/views/layouts/_guide.html.erb | 2 +- app/views/layouts/_progress_listing.html.erb | 10 +++++----- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 0c92b68c59..356aa88970 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -7,9 +7,9 @@ def fixed_fa_icon(name, options = {}) fa_icon name, options.merge(class: 'fa-fw fixed-icon') end - def exercise_status_icon(exercise) - link_to exercise_status_fa_icon(exercise), - exercise_path(exercise) if current_user? + def assignment_status_icon(assignment) + link_to contextualization_fa_icon(assignment), + exercise_path(assignment.exercise) if current_user? end def language_icon(language) @@ -22,10 +22,6 @@ def contextualization_fa_icon(contextualization) fa_icon(*icon_for(contextualization)) end - def exercise_status_fa_icon(exercise) - contextualization_fa_icon(exercise.assignment_for(current_user)) - end - def discussion_status_fa_icon(discussion) contextualization_fa_icon(discussion) end diff --git a/app/views/chapters/show.html.erb b/app/views/chapters/show.html.erb index 1fe8be2073..4a3dfb5141 100644 --- a/app/views/chapters/show.html.erb +++ b/app/views/chapters/show.html.erb @@ -28,7 +28,7 @@ <% @chapter.lessons.includes(guide: :exercises).each do |lesson| %>

<%= lesson.number %>. <%= link_to_path_element lesson, mode: :plain %>

- <%= render partial: 'layouts/progress_listing', locals: { exercises: lesson.exercises } %> + <%= render partial: 'layouts/progress_listing', locals: { guide: lesson.guide } %> <% end %>
<% end %> diff --git a/app/views/layouts/_guide.html.erb b/app/views/layouts/_guide.html.erb index 4726ac48e2..46822c0d68 100644 --- a/app/views/layouts/_guide.html.erb +++ b/app/views/layouts/_guide.html.erb @@ -13,7 +13,7 @@ <%= restart_guide_link(@guide) if current_user && @guide.started?(current_user) && @guide.resettable? %> -<%= render partial: 'layouts/progress_listing', locals: {exercises: @guide.exercises} %> +<%= render partial: 'layouts/progress_listing', locals: { guide: @guide } %> <% if @stats&.done? %>
diff --git a/app/views/layouts/_progress_listing.html.erb b/app/views/layouts/_progress_listing.html.erb index d0bace21b7..6cce14a771 100644 --- a/app/views/layouts/_progress_listing.html.erb +++ b/app/views/layouts/_progress_listing.html.erb @@ -1,9 +1,9 @@
From b78a45a04f889942abd253786cc056d968d3342e Mon Sep 17 00:00:00 2001 From: Franco Leonardo Bulgarelli Date: Sat, 30 Jan 2021 19:39:42 -0300 Subject: [PATCH 12/13] Update domain --- Gemfile | 3 --- mumuki-laboratory.gemspec | 2 +- spec/dummy/db/schema.rb | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index f38fc0840b..7e379383cc 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,3 @@ group :development, :test do gem 'teaspoon-jasmine' gem 'selenium-webdriver' end - - -gem "mumuki-domain", github: "mumuki/mumuki-domain", branch: "chore-database-optimization" \ No newline at end of file diff --git a/mumuki-laboratory.gemspec b/mumuki-laboratory.gemspec index 4c7612867b..82246dad79 100644 --- a/mumuki-laboratory.gemspec +++ b/mumuki-laboratory.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_dependency "rails", "~> 5.1.6" - s.add_dependency 'mumuki-domain', '~> 8.3.0' + s.add_dependency 'mumuki-domain', '~> 8.4.0' s.add_dependency 'mumukit-bridge', '~> 4.1' s.add_dependency 'mumukit-login', '~> 7.3' s.add_dependency 'mumukit-nuntius', '~> 6.1' diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 40f638bb85..df36d31055 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -482,6 +482,7 @@ t.datetime "legal_terms_accepted_at" t.datetime "forum_terms_accepted_at" t.boolean "banned_from_forum" + t.boolean "uppercase_mode" t.index ["avatar_type", "avatar_id"], name: "index_users_on_avatar_type_and_avatar_id" t.index ["disabled_at"], name: "index_users_on_disabled_at" t.index ["last_organization_id"], name: "index_users_on_last_organization_id" From b2d471d1f63a393fbb997d8c5b993f737976e909 Mon Sep 17 00:00:00 2001 From: Franco Leonardo Bulgarelli Date: Sat, 30 Jan 2021 19:40:26 -0300 Subject: [PATCH 13/13] 4th optimization: cache progress items --- app/views/layouts/_progress_bar.html.erb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/views/layouts/_progress_bar.html.erb b/app/views/layouts/_progress_bar.html.erb index 168707b110..7f072d87a5 100644 --- a/app/views/layouts/_progress_bar.html.erb +++ b/app/views/layouts/_progress_bar.html.erb @@ -2,13 +2,15 @@ <% assignments = guide.assignments_for(current_user) %> <% assignments.each do |assignment| %> <% exercise = assignment.exercise %> - - href="<%= exercise_path(exercise)%>" - aria-label="<%= exercise.navigable_name %>" - title="<%= exercise.navigable_name %>" - data-mu-exercise-id="<%= exercise.id %>" - class="<%= class_for_progress_list_item(assignment, exercise == current)%>"> - + <% cache [:progress_list_item, exercise, assignment.status, Organization.current, exercise == current] do %> + + href="<%= exercise_path(exercise)%>" + aria-label="<%= exercise.navigable_name %>" + title="<%= exercise.navigable_name %>" + data-mu-exercise-id="<%= exercise.id %>" + class="<%= class_for_progress_list_item(assignment, exercise == current)%>"> + + <% end %> <% end %> - + \ No newline at end of file