Skip to content

Commit

Permalink
Merge pull request #864 from MITLibraries/publication_status_report
Browse files Browse the repository at this point in the history
Resolve N+1 queries in pub status report and index
  • Loading branch information
JPrevost authored Jan 14, 2022
2 parents b97f5c6 + a3cb95d commit d8b507e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ group :development do
gem 'listen'
gem 'rubocop'
gem 'rubocop-rails'
gem 'scout_apm'
gem 'web-console'
end

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
scout_apm (5.1.1)
parser
selectize-rails (0.12.6)
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
Expand Down Expand Up @@ -407,6 +409,7 @@ DEPENDENCIES
rubocop
rubocop-rails
sass-rails
scout_apm
selenium-webdriver
sentry-rails
sentry-ruby
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ this automatically. It is often nice in development as well.
`MAINTAINER_EMAIL` - used for `to` field of virus detected emails.
`THESIS_ADMIN_EMAIL` - used for `from` field of receipt emails. Also the email to which reports are sent.
`MAINTAINER_EMAIL` - used for `cc` field of report emails.
`SCOUT_DEV_TRACE` - include this and set it to `true` to enable perfomance monitoring in development. Very useful to
track down N+1 queries!

### Production

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/thesis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def publication_statuses
@terms = defined_terms Thesis.all
@publication_statuses = Thesis.all.pluck(:publication_status).uniq.sort
# Filter relevant theses by selected term from querystring
term_filtered = filter_theses_by_term Thesis.all
term_filtered = filter_theses_by_term Thesis.all.includes(:degrees, :departments, :users)
@thesis = filter_theses_by_publication_status term_filtered
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def data_student_contributions
row_data = {}
terms = Thesis.all.pluck(:grad_date).uniq.sort
terms.each do |term|
row_data[term] = Thesis.where('grad_date = ?', term).map(&:student_contributed?).count(true)
row_data[term] = Thesis.where('grad_date = ?', term).includes(:versions).map(&:student_contributed?).count(true)
end
{
label: 'Students contributing',
Expand Down

0 comments on commit d8b507e

Please sign in to comment.