Skip to content

Commit

Permalink
feat: optimise latest_pact_consumer_version_orders
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 27, 2019
1 parent d92cb8f commit c4febea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
13 changes: 13 additions & 0 deletions db/ddl_statements/latest_pact_consumer_version_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def latest_pact_consumer_version_orders_v1(connection = nil)
"select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order
from all_pact_publications
group by provider_id, consumer_id"
end

def latest_pact_consumer_version_orders_v2(connection = nil)
view = Sequel.as(:latest_pact_publication_ids_for_consumer_versions, :lp)
connection.from(view)
.select_group(:consumer_id, :provider_id)
.select_append{ max(order).as(latest_consumer_version_order) }
.join(:versions, { Sequel[:lp][:consumer_version_id] => Sequel[:cv][:id]}, { table_alias: :cv} )
end
5 changes: 1 addition & 4 deletions db/migrations/20180722_recreate_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
)

create_or_replace_view(:latest_pact_consumer_version_orders,
"select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order
from all_pact_publications
group by provider_id, consumer_id"
)
latest_pact_consumer_version_orders_v1(self))
end
end
13 changes: 13 additions & 0 deletions db/migrations/20191029_optimise_latest_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_pact_consumer_version_orders,
latest_pact_consumer_version_orders_v2(self))
end

down do
create_or_replace_view(:latest_pact_consumer_version_orders,
latest_pact_consumer_version_orders_v1(self))
end
end

0 comments on commit c4febea

Please sign in to comment.