From 1315e0b1924cb6f42751f977789be3559373033a Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 15 Apr 2019 12:11:13 +1000 Subject: [PATCH] feat: batch delete versions and tags using delete instead of destroy for efficiency --- lib/pact_broker/domain/version.rb | 5 +++++ lib/pact_broker/pacts/repository.rb | 2 +- lib/pact_broker/verifications/repository.rb | 2 +- lib/pact_broker/versions/repository.rb | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pact_broker/domain/version.rb b/lib/pact_broker/domain/version.rb index f633b3492..5002f187b 100644 --- a/lib/pact_broker/domain/version.rb +++ b/lib/pact_broker/domain/version.rb @@ -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 diff --git a/lib/pact_broker/pacts/repository.rb b/lib/pact_broker/pacts/repository.rb index f12cdaf1d..00a7b6e97 100644 --- a/lib/pact_broker/pacts/repository.rb +++ b/lib/pact_broker/pacts/repository.rb @@ -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 diff --git a/lib/pact_broker/verifications/repository.rb b/lib/pact_broker/verifications/repository.rb index 3a3dee358..40417d10e 100644 --- a/lib/pact_broker/verifications/repository.rb +++ b/lib/pact_broker/verifications/repository.rb @@ -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 diff --git a/lib/pact_broker/versions/repository.rb b/lib/pact_broker/versions/repository.rb index 04a46f636..48771c960 100644 --- a/lib/pact_broker/versions/repository.rb +++ b/lib/pact_broker/versions/repository.rb @@ -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