From 2a57dc42a69db9ea049950fc23070d8929a02642 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 23 Nov 2022 14:12:50 +1100 Subject: [PATCH] fix(versions): eager load associations for versions endpoint --- lib/pact_broker/pacticipants/repository.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/pacticipants/repository.rb b/lib/pact_broker/pacticipants/repository.rb index 7d8b86bc4..3b61e4f1f 100644 --- a/lib/pact_broker/pacticipants/repository.rb +++ b/lib/pact_broker/pacticipants/repository.rb @@ -38,9 +38,15 @@ def find options = {} def find_all_pacticipant_versions_in_reverse_order name, pagination_options = nil pacticipant = pacticipant_repository.find_by_name!(name) - query = PactBroker::Domain::Version.where(pacticipant: pacticipant).reverse_order(:order) + query = PactBroker::Domain::Version + .where(pacticipant: pacticipant) + .eager(:pacticipant) + .eager(branch_versions: [:version, :branch_head, { branch: :pacticipant }]) + .eager(tags: :head_tag) + .eager(:pact_publications) + .reverse_order(:order) query = query.paginate(pagination_options[:page_number], pagination_options[:page_size]) if pagination_options - query + query.all end def find_by_name_or_create name