Skip to content

Commit

Permalink
feat: optimise latest_tagged_pact_consumer_version_orders view
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 27, 2019
1 parent 5f12487 commit d92cb8f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
23 changes: 23 additions & 0 deletions db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def latest_tagged_pact_consumer_version_orders_v2(connection)
pp = :pact_publications
connection.from(pp)
.select_group(
Sequel[pp][:provider_id],
Sequel[:cv][:pacticipant_id].as(:consumer_id),
Sequel[:t][:name].as(:tag_name))
.select_append{ max(order).as(latest_consumer_version_order) }
.join(:versions, { Sequel[pp][:consumer_version_id] => Sequel[:cv][:id] }, { table_alias: :cv} )
.join(:tags, { Sequel[:t][:version_id] => Sequel[pp][:consumer_version_id] }, { table_alias: :t })
end

def latest_tagged_pact_consumer_version_orders_v3(connection)
view = Sequel.as(:latest_pact_publication_ids_for_consumer_versions, :lp)
connection.from(view)
.select_group(
Sequel[:lp][:provider_id],
Sequel[:cv][:pacticipant_id].as(:consumer_id),
Sequel[:t][:name].as(:tag_name))
.select_append{ max(order).as(latest_consumer_version_order) }
.join(:versions, { Sequel[:lp][:consumer_version_id] => Sequel[:cv][:id] }, { table_alias: :cv} )
.join(:tags, { Sequel[:t][:version_id] => Sequel[:lp][:consumer_version_id] }, { table_alias: :t })
end
10 changes: 1 addition & 9 deletions db/migrations/20180311_optimise_head_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@
pp = :pact_publications
# For each consumer_id/provider_id/tag_name, the version order of the latest version that has a pact
create_or_replace_view(:latest_tagged_pact_consumer_version_orders,
from(:pact_publications)
.select_group(
Sequel[pp][:provider_id],
Sequel[:cv][:pacticipant_id].as(:consumer_id),
Sequel[:t][:name].as(:tag_name))
.select_append{ max(order).as(latest_consumer_version_order) }
.join(:versions, { Sequel[pp][:consumer_version_id] => Sequel[:cv][:id] }, { table_alias: :cv} )
.join(:tags, { Sequel[:t][:version_id] => Sequel[pp][:consumer_version_id] }, { table_alias: :t })
)
latest_tagged_pact_consumer_version_orders_v2(self))

# Add provider_version_order to original definition
# The most recent verification for each pact_version
Expand Down
13 changes: 13 additions & 0 deletions db/migrations/20191028_optimise_latest_tagged_pact_cv_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_relative '../ddl_statements'

Sequel.migration do
up do
create_or_replace_view(:latest_tagged_pact_consumer_version_orders,
latest_tagged_pact_consumer_version_orders_v3(self))
end

down do
create_or_replace_view(:latest_tagged_pact_consumer_version_orders,
latest_tagged_pact_consumer_version_orders_v2(self))
end
end

0 comments on commit d92cb8f

Please sign in to comment.