Skip to content

Commit

Permalink
feat: add index to verifications table to improve performance of 'lat…
Browse files Browse the repository at this point in the history
…est verification' query
  • Loading branch information
bethesque committed Aug 15, 2021
1 parent 0b2d21f commit 02eeb42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Sequel.migration do
change do
alter_table(:verifications) do
add_index([:pact_version_id, :id], name: "verifications_pact_version_id_id_index")
end
end
end
3 changes: 2 additions & 1 deletion lib/pact_broker/pacts/pact_version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "sequel"
require "pact_broker/repositories/helpers"
require "pact_broker/verifications/latest_verification_for_pact_version"
require "pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version"

module PactBroker
module Pacts
Expand All @@ -17,7 +18,7 @@ class PactVersion < Sequel::Model(:pact_versions)
one_to_one(:latest_verification,
class: "PactBroker::Domain::Verification",
read_only: true,
dataset: lambda { PactBroker::Domain::Verification.where(id: PactBroker::Domain::Verification.select(Sequel.function(:max, :id)).where(pact_version_id: id)) },
dataset: lambda { PactBroker::Domain::Verification.where(id: PactBroker::Verifications::LatestVerificationIdForPactVersionAndProviderVersion.select(Sequel.function(:max, :verification_id)).where(pact_version_id: id)) },
key: :pact_version_id, primary_key: :id,
eager_block: lambda { | ds | ds.latest_by_pact_version }
)
Expand Down

0 comments on commit 02eeb42

Please sign in to comment.