Skip to content

Commit b6b5c90

Browse files
committed
feat(dashboard api): eager load the pact_version
1 parent f27a718 commit b6b5c90

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/pact_broker/integrations/integration.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Integration < Sequel::Model
88
associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id)
99
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id)
1010
associate(:one_to_one, :latest_pact, :class => "PactBroker::Pacts::LatestPactPublications", key: [:consumer_id, :provider_id], primary_key: [:consumer_id, :provider_id])
11+
associate(:one_to_one, :latest_verification, :class => "PactBroker::Verifications::LatestVerificationForConsumerAndProvider", key: [:consumer_id, :provider_id], primary_key: [:consumer_id, :provider_id])
1112

1213
def verification_status_for_latest_pact
1314
@verification_status_for_latest_pact ||= PactBroker::Verifications::PseudoBranchStatus.new(latest_pact, latest_pact&.latest_verification)
@@ -18,7 +19,7 @@ def latest_pact_or_verification_publication_date
1819
end
1920

2021
def latest_verification_publication_date
21-
PactBroker::Domain::Verification.where(consumer_id: consumer_id, provider_id: provider_id).order(:id).last&.execution_date
22+
latest_verification&.execution_date
2223
end
2324
end
2425
end

lib/pact_broker/integrations/service.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ class Service
1111
include PactBroker::Logging
1212

1313
def self.find_all
14+
# The only reason the pact_version needs to be loaded is that
15+
# the Verification::PseudoBranchStatus uses it to determine if
16+
# the pseudo branch is 'stale'.
17+
# Because this is the status for a pact, and not a pseudo branch,
18+
# the status can never be 'stale',
19+
# so it would be better to create a Verification::PactStatus class
20+
# that doesn't have the 'stale' logic in it.
21+
# Then we can remove the eager loading of the pact_version
1422
PactBroker::Integrations::Integration
1523
.eager(:consumer)
1624
.eager(:provider)
17-
.eager(latest_pact: :latest_verification)
25+
.eager(latest_pact: [:latest_verification, :pact_version])
26+
.eager(:latest_verification)
1827
.all
1928
.sort { | a, b| b.latest_pact_or_verification_publication_date <=> a.latest_pact_or_verification_publication_date }
2029
end

spec/lib/pact_broker/integrations/integration_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ module Integrations
2929
expect(Integration.first.verification_status_for_latest_pact).to be_instance_of(PactBroker::Verifications::PseudoBranchStatus)
3030
end
3131

32+
it "has a latest verification - this may not be the same as the latest verification for the latest pact" do
33+
integration = Integration.eager(:latest_verification).all.first
34+
expect(integration.latest_verification.provider_version_number).to eq "4"
35+
end
36+
3237
describe "latest_pact_or_verification_publication_date" do
3338
context "when the last publication is a verification" do
3439
it "returns the verification execution date" do

0 commit comments

Comments
 (0)