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/boards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BoardsController < ApplicationController
before_action :ensure_permission_to_admin_board, only: %i[ update destroy ]

def index
set_page_and_extract_portion_from Current.user.boards.ordered_by_recently_accessed
set_page_and_extract_portion_from Current.user.boards.ordered_by_recently_accessed.includes(creator: :identity)
fresh_when etag: @page.records
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class UsersController < ApplicationController
before_action :ensure_permission_to_change_user, only: %i[ update destroy ]

def index
set_page_and_extract_portion_from Current.account.users.active.alphabetically
set_page_and_extract_portion_from Current.account.users.active.alphabetically.includes(:identity)
end

def show
Expand Down
14 changes: 14 additions & 0 deletions test/controllers/boards_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
assert_response :no_content
end

test "index avoids N+1 queries on creator and identity" do
assert_queries_match(/FROM [`"]users[`"].* IN \(/, count: 1) do
assert_queries_match(/FROM [`"]identities[`"].* IN \(/, count: 1) do
get boards_path, as: :json
assert_response :success
end
end

json = @response.parsed_body
first_board = json.first
assert first_board["creator"].present?
assert first_board["creator"]["email_address"].present?
end

private
def next_page_from_link_header(link_header)
url = link_header&.match(/<([^>]+)>;\s*rel="next"/)&.captures&.first
Expand Down
12 changes: 12 additions & 0 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,16 @@ class UsersControllerTest < ActionDispatch::IntegrationTest

assert_response :no_content
end

test "index avoids N+1 queries on identity" do
sign_in_as :kevin

assert_queries_match(/FROM [`"]identities[`"].* IN \(/, count: 1) do
get users_path, as: :json
assert_response :success
end

json = @response.parsed_body
assert json.first["email_address"].present?
end
end