-
-
Notifications
You must be signed in to change notification settings - Fork 174
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_tagged_pact_consumer_version_orders view
- Loading branch information
Showing
3 changed files
with
37 additions
and
9 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb
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,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 |
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
13 changes: 13 additions & 0 deletions
13
db/migrations/20191028_optimise_latest_tagged_pact_cv_orders.rb
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_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 |