diff --git a/Gemfile b/Gemfile index f4732a95..bd58f0d4 100644 --- a/Gemfile +++ b/Gemfile @@ -74,6 +74,7 @@ group :development do gem "bullet" gem "hotwire-spark" gem "letter_opener" + gem "rack-mini-profiler" # Use console on exceptions pages [https://github.com/rails/web-console] gem "web-console" end diff --git a/Gemfile.lock b/Gemfile.lock index 506f7503..892cb9a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -309,6 +309,8 @@ GEM raabro (1.4.0) racc (1.8.1) rack (3.1.16) + rack-mini-profiler (4.0.0) + rack (>= 1.2.0) rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) @@ -519,6 +521,7 @@ DEPENDENCIES pg (~> 1.1) propshaft puma (>= 5.0) + rack-mini-profiler rails (~> 8.0.1) rails-controller-testing requestjs-rails diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 0017d7d6..8f514928 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -5,7 +5,7 @@ class TopicsController < ApplicationController before_action :set_topic, only: [ :show, :edit, :tags, :update, :destroy, :archive ] def index - @pagy, @topics = pagy(scope.search_with_params(search_params)) + @pagy, @topics = pagy(scope.includes(:documents_attachments).search_with_params(search_params)) @available_providers = other_available_providers @languages = scope.map(&:language).uniq.sort_by(&:name) end diff --git a/app/views/topics/_list.html.erb b/app/views/topics/_list.html.erb index 4e9a75ed..6e11e661 100644 --- a/app/views/topics/_list.html.erb +++ b/app/views/topics/_list.html.erb @@ -6,6 +6,7 @@ <%= topic.uid.truncate(10, omission: "...") if topic.uid %> <%= topic.language.name %> <%= topic.provider.name %> + <%= topic.documents.size %> <%= topic.state %> <%= link_to topic, class: "btn btn-primary btn-sm", data: {turbo: false } do %> diff --git a/app/views/topics/index.html.erb b/app/views/topics/index.html.erb index 2328aba1..894691a2 100644 --- a/app/views/topics/index.html.erb +++ b/app/views/topics/index.html.erb @@ -28,6 +28,7 @@ UID Language Provider + Training
Materials State Actions diff --git a/config/environments/development.rb b/config/environments/development.rb index ab79899e..f9967eec 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -88,4 +88,5 @@ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. # config.generators.apply_rubocop_autocorrect_after_generate! + Bullet.add_safelist type: :unused_eager_loading, class_name: "Topic", association: :documents_attachments end diff --git a/spec/requests/topics/index_spec.rb b/spec/requests/topics/index_spec.rb index beb7190c..3f36d4a4 100644 --- a/spec/requests/topics/index_spec.rb +++ b/spec/requests/topics/index_spec.rb @@ -19,6 +19,14 @@ expect(assigns(:topics)).to eq([ topic ]) end + it "displays the number of documents" do + topic = create(:topic, :with_documents, provider:) + + get topics_url + + expect(page).to have_css("td", text: "1") + end + describe "searching" do context "with a query" do it "filters topics by query" do