-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimise latest_pact_consumer_version_orders
- Loading branch information
Showing
3 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |