Skip to content

Commit

Permalink
feat: optimise latest_pact_publications_by_consumer_versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 27, 2019
1 parent b4b0324 commit 8684627
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
16 changes: 16 additions & 0 deletions db/ddl_statements/latest_pact_publications_by_consumer_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def latest_pact_publications_by_consumer_versions_v2(connection = nil)
"select app.*
from latest_pact_publication_ids_for_consumer_versions lpp
inner join all_pact_publications app
on lpp.consumer_version_id = app.consumer_version_id
and lpp.pact_publication_id = app.id
and lpp.provider_id = app.provider_id"
end

# Don't need all the join keys, just pact_publication_id
def latest_pact_publications_by_consumer_versions_v3(connection)
"select app.*
from latest_pact_publication_ids_for_consumer_versions lpp
inner join all_pact_publications app
on lpp.pact_publication_id = app.id"
end
1 change: 1 addition & 0 deletions db/migrations/000028_create_all_pact_publications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

# Latest pact_publication (revision) for each provider/consumer version
# updated in 20180519_recreate_views.rb
# latest_pact_publications_by_consumer_versions_v1
create_view(:latest_pact_publications_by_consumer_versions,
"select app.*
from all_pact_publications app
Expand Down
11 changes: 4 additions & 7 deletions db/migrations/20180722_recreate_views.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
require_relative '../ddl_statements'

Sequel.migration do
up do
# Latest pact_publication details for each provider/consumer version
create_or_replace_view(:latest_pact_publications_by_consumer_versions,
"select app.*
from latest_pact_publication_ids_for_consumer_versions lpp
inner join all_pact_publications app
on lpp.consumer_version_id = app.consumer_version_id
and lpp.pact_publication_id = app.id
and lpp.provider_id = app.provider_id"
)
latest_pact_publications_by_consumer_versions_v2(self))

# Latest consumer version order for consumer/provider
# Recreate latest_pact_publication_ids_for_consumer_versions view
Expand All @@ -17,6 +13,7 @@

down do
# Latest pact_publication details for each provider/consumer version
# latest_pact_publications_by_consumer_versions_v1
create_or_replace_view(:latest_pact_publications_by_consumer_versions,
"select app.*
from all_pact_publications app
Expand Down
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_publications_by_consumer_versions,
latest_pact_publications_by_consumer_versions_v3(self))
end

down do
create_or_replace_view(:latest_pact_publications_by_consumer_versions,
latest_pact_publications_by_consumer_versions_v2(self))
end
end

0 comments on commit 8684627

Please sign in to comment.