Skip to content

Commit

Permalink
feat(matrix): optimise identification of the 'latest tag'
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 4, 2023
1 parent 662398c commit 824c516
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 58 deletions.
1 change: 0 additions & 1 deletion lib/pact_broker/domain/verification.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "pact_broker/dataset"
require "json"
require "pact_broker/tags/tag_with_latest_flag"
require "pact_broker/pacts/content"
require "sequel/extensions/symbol_aref_refinement"

Expand Down
16 changes: 0 additions & 16 deletions lib/pact_broker/domain/version.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
require "pact_broker/dataset"
require "pact_broker/domain/order_versions"
require "pact_broker/tags/tag_with_latest_flag"
require "pact_broker/versions/eager_loaders"

module PactBroker
module Domain

# Same attributes as PactBroker::Tags::TagWithLatestFlag
class EagerTagWithLatestFlag < SimpleDelegator
attr_reader :latest

def initialize(tag, latest)
super(tag)
@latest = latest
end

def latest?
latest
end
end

VERSION_COLUMNS = [:id, :number, :repository_ref, :pacticipant_id, :order, :created_at, :updated_at, :build_url]

class Version < Sequel::Model(Sequel::Model.db[:versions].select(*VERSION_COLUMNS.collect{ | column | Sequel.qualify(:versions, column) }))
Expand Down
5 changes: 2 additions & 3 deletions lib/pact_broker/matrix/every_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ class Verification < Sequel::Model(:verifications)
associate(:many_to_one, :provider_version, :class => "PactBroker::Domain::Version", :key => :provider_version_id, :primary_key => :id)
associate(:many_to_one, :pact_version, class: "PactBroker::Pacts::PactVersion", :key => :pact_version_id, :primary_key => :id)
associate(:many_to_one, :verification, class: "PactBroker::Domain::Verification", :key => :verification_id, :primary_key => :id)
associate(:one_to_many, :consumer_version_tags, :class => "PactBroker::Tags::TagWithLatestFlag", primary_key: :consumer_version_id, key: :version_id)
associate(:one_to_many, :provider_version_tags, :class => "PactBroker::Tags::TagWithLatestFlag", primary_key: :provider_version_id, key: :version_id)

associate(:one_to_many, :consumer_version_tags, :class => "PactBroker::Domain::Tag", primary_key: :consumer_version_id, key: :version_id)
associate(:one_to_many, :provider_version_tags, :class => "PactBroker::Domain::Tag", primary_key: :provider_version_id, key: :version_id)

PACT_COLUMNS_WITH_ALIASES = [
Sequel[:p][:consumer_id],
Expand Down
6 changes: 3 additions & 3 deletions lib/pact_broker/matrix/matrix_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
require "pact_broker/domain/pacticipant"
require "pact_broker/domain/version"
require "pact_broker/domain/verification"
require "pact_broker/domain/tag"
require "pact_broker/pacts/pact_publication"
require "pact_broker/tags/tag_with_latest_flag"
require "pact_broker/matrix/matrix_row_dataset_module"
require "pact_broker/matrix/matrix_row_instance_methods"
require "pact_broker/matrix/matrix_row_verification_dataset_module"
Expand Down Expand Up @@ -66,8 +66,8 @@ class Verification < Sequel::Model(Sequel.as(:latest_verification_id_for_pact_ve
associate(:many_to_one, :provider_version, :class => "PactBroker::Domain::Version", :key => :provider_version_id, :primary_key => :id)
associate(:many_to_one, :pact_version, class: "PactBroker::Pacts::PactVersion", :key => :pact_version_id, :primary_key => :id)
associate(:many_to_one, :verification, class: "PactBroker::Domain::Verification", :key => :verification_id, :primary_key => :id)
associate(:one_to_many, :consumer_version_tags, :class => "PactBroker::Tags::TagWithLatestFlag", primary_key: :consumer_version_id, key: :version_id)
associate(:one_to_many, :provider_version_tags, :class => "PactBroker::Tags::TagWithLatestFlag", primary_key: :provider_version_id, key: :version_id)
associate(:one_to_many, :consumer_version_tags, :class => "PactBroker::Domain::Tag", primary_key: :consumer_version_id, key: :version_id)
associate(:one_to_many, :provider_version_tags, :class => "PactBroker::Domain::Tag", primary_key: :provider_version_id, key: :version_id)

dataset_module do
include PactBroker::Dataset
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/matrix/matrix_row_dataset_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def eager_all_the_things
:pact_version,
consumer_version: EAGER_LOADED_RELATIONSHIPS_FOR_VERSION,
provider_version: EAGER_LOADED_RELATIONSHIPS_FOR_VERSION,
consumer_version_tags: { version: :pacticipant },
provider_version_tags: { version: :pacticipant }
consumer_version_tags: [:head_tag, { version: :pacticipant }],
provider_version_tags: [:head_tag, { version: :pacticipant }]
)
end

Expand Down
24 changes: 0 additions & 24 deletions lib/pact_broker/tags/tag_with_latest_flag.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def consumer_version_branches

def latest_consumer_version_tags
@line.consumer_version_tags
.select(&:latest)
.select(&:latest?)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) }
end

def other_consumer_version_tags
@line.consumer_version_tags
.reject(&:latest)
.reject(&:latest?)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) }
end
Expand All @@ -138,14 +138,14 @@ def provider_version_branches

def latest_provider_version_tags
@line.provider_version_tags
.select(&:latest)
.select(&:latest?)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: provider_name, version_number: provider_version_number)) }
end

def other_provider_version_tags
@line.provider_version_tags
.reject(&:latest)
.reject(&:latest?)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: provider_name, version_number: provider_version_number)) }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Decorators
)
end

let(:provider_version_tags) { [instance_double(PactBroker::Tags::TagWithLatestFlag, name: "prod", latest?: true)] }
let(:provider_version_tags) { [instance_double(PactBroker::Domain::Tag, name: "prod", latest?: true)] }

let(:options) { { user_options: { base_url: "http://example.org", pact: pact } } }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Decorators
instance_double("PactBroker::Pacts::PactVersion", name: "Name")
end

let(:provider_version_tags) { [instance_double(PactBroker::Tags::TagWithLatestFlag, name: "prod", latest?: true)] }
let(:provider_version_tags) { [instance_double(PactBroker::Domain::Tag, name: "prod", latest?: true)] }
let(:pact) { instance_double("PactBroker::Domain::Pact", name: "Some pact", consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "1.2.3", pact_version_sha: "1234") }
let(:is_pending) { true }
let(:options) { {base_url: "http://example.org", consumer_name: "Foo", consumer_version_number: "1.2.3", resource_url: "http://self"} }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/matrix/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def shorten_rows rows
end

it "returns the tag information" do
expect(subject.first.provider_version_tags).to include_hash_matching name: "prod", latest: 1
expect(subject.first.provider_version_tags).to include(have_attributes(name: "prod", latest?: true))
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pact_broker/ui/view_models/index_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module ViewDomain
let(:latest_verification) { instance_double("PactBroker::Domain::Verification") }
let(:domain_relationship) { PactBroker::Domain::IndexItem.new(consumer, provider, consumer_version, latest_pact, latest, latest_verification, [], [], tags, latest_verification_latest_tags)}
let(:tags) { [] }
let(:verification_tag_1) { instance_double("PactBroker::Tags::TagWithLatestFlag", name: "dev") }
let(:verification_tag_2) { instance_double("PactBroker::Tags::TagWithLatestFlag", name: "prod") }
let(:verification_tag_1) { instance_double("PactBroker::Domain::Tag", name: "dev") }
let(:verification_tag_2) { instance_double("PactBroker::Domain::Tag", name: "prod") }
let(:latest_verification_latest_tags) { [verification_tag_1, verification_tag_2] }
let(:latest) { true }

Expand Down

0 comments on commit 824c516

Please sign in to comment.