Skip to content

Commit

Permalink
feat: batch delete versions and tags using delete instead of destroy …
Browse files Browse the repository at this point in the history
…for efficiency
  • Loading branch information
bethesque committed Apr 15, 2019
1 parent f31e8df commit 1315e0b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/pact_broker/domain/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Version < Sequel::Model

dataset_module do
include PactBroker::Repositories::Helpers

def delete
PactBroker::Domain::Tag.where(version: self).delete
super
end
end

def after_create
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def delete_all_pact_publications_between consumer_name, options
def delete_all_pact_versions_between consumer_name, options
consumer = pacticipant_repository.find_by_name(consumer_name)
provider = pacticipant_repository.find_by_name(options.fetch(:and))
PactVersion.where(consumer: consumer, provider: provider).destroy
PactVersion.where(consumer: consumer, provider: provider).delete
end

def find_latest_pact_versions_for_provider provider_name, tag = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/verifications/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def delete_by_provider_version_id version_id
def delete_all_verifications_between(consumer_name, options)
consumer = pacticipant_repository.find_by_name(consumer_name)
provider = pacticipant_repository.find_by_name(options.fetch(:and))
PactBroker::Domain::Verification.where(provider: provider, consumer: consumer).destroy
PactBroker::Domain::Verification.where(provider: provider, consumer: consumer).delete
end

def pact_version_id_for pact
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/versions/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def delete_orphan_versions consumer, provider
PactBroker::Domain::Version
.where(pacticipant_id: [consumer.id, provider.id])
.exclude(id: (version_ids_with_pact_publications + version_ids_with_verifications).uniq)
.destroy
.delete
end
end
end
Expand Down

0 comments on commit 1315e0b

Please sign in to comment.