Skip to content

Commit

Permalink
chore: extract eager loaded version relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 17, 2022
1 parent bdc2599 commit 21bd33c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/pact_broker/matrix/quick_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
SELECT_ALL_COLUMN_ARGS = [:select_all_columns] + ALL_COLUMNS
SELECT_PACTICIPANT_IDS_ARGS = [:select_pacticipant_ids, Sequel[:p][:consumer_id], Sequel[:p][:provider_id]]

EAGER_LOADED_RELATIONSHIPS_FOR_VERSION = { current_deployed_versions: :environment, current_supported_released_versions: :environment, branch_versions: [:branch_head, :version, branch: :pacticipant] }

associate(:many_to_one, :pact_publication, :class => "PactBroker::Pacts::PactPublication", :key => :pact_publication_id, :primary_key => :id)
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id)
associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id)
Expand Down Expand Up @@ -141,15 +143,16 @@ def order_by_pact_publication_created_at
order(Sequel.desc(:consumer_version_created_at), Sequel.desc(:pact_order))
end

# eager load tags?
def eager_all_the_things
eager(
:consumer,
:provider,
:verification,
:pact_publication,
:pact_version,
consumer_version: { current_deployed_versions: :environment, current_supported_released_versions: :environment, branch_versions: [:branch_head, :version, branch: :pacticipant] },
provider_version: { current_deployed_versions: :environment, current_supported_released_versions: :environment, branch_versions: [:branch_head, :version, branch: :pacticipant] },
consumer_version: EAGER_LOADED_RELATIONSHIPS_FOR_VERSION,
provider_version: EAGER_LOADED_RELATIONSHIPS_FOR_VERSION,
consumer_version_tags: { version: :pacticipant },
provider_version_tags: { version: :pacticipant }
)
Expand Down

0 comments on commit 21bd33c

Please sign in to comment.