Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/judge_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
.includes(contest_instance: [
contest_description: [ :container ],
judging_rounds: [ :round_judge_assignments ],
entries: [ :entry_rankings ]
entries: [ :entry_rankings, :category, { entry_file_attachment: :blob } ]
])
.where(judging_assignments: { active: true })
.where(contest_instances: { active: true, id: contest_instances_with_incomplete_assigned_rounds })
Expand Down
2 changes: 2 additions & 0 deletions app/views/judge_dashboard/_available_entries.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
).pluck(:entry_id) %>

<% assignment.contest_instance.current_round_entries
.with_attached_entry_file
.includes(:category)
.where.not(id: ranked_entry_ids)
.each do |entry| %>
<%= turbo_frame_tag dom_id(entry) do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/judge_dashboard/_selected_entries.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Please select and rank <%= assignment.contest_instance.current_judging_round.required_entries_count %> entries
</div>
<div class="rated-entries" data-entry-drag-target="ratedEntries">
<% EntryRanking.includes(:entry)
<% EntryRanking.includes(entry: [ :category, { entry_file_attachment: :blob } ])
.where(judging_round: assignment.contest_instance.current_judging_round, user: current_user)
.order(:rank)
.each do |ranking| %>
Expand Down
22 changes: 22 additions & 0 deletions spec/controllers/judge_dashboard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@
end
end

context 'when judge is assigned and index renders entries with attachments' do
before do
create(:judging_assignment, user: judge, contest_instance: contest_instance, active: true)
create(:round_judge_assignment, user: judge, judging_round: round_1, active: true)
create_list(:entry, 3, contest_instance: contest_instance, deleted: false)
end

it 'eager loads entry_file attachments to avoid N+1 queries' do
attachment_queries = 0
counter = ActiveSupport::Notifications.subscribe('sql.active_record') do |_name, _start, _finish, _id, payload|
attachment_queries += 1 if payload[:sql] =~ /active_storage_attachments/
end

get :index

ActiveSupport::Notifications.unsubscribe(counter)

# With eager loading we should have at most 2 queries (attachments + blobs), not one per entry
expect(attachment_queries).to be <= 2
end
end

context 'when judge is assigned to contest but no rounds' do
before do
create(:judging_assignment, user: judge, contest_instance: contest_instance, active: true)
Expand Down