From 707b2642b215685ad52b44d629e493e054a66d83 Mon Sep 17 00:00:00 2001 From: "Marcos G. Zimmermann" Date: Fri, 12 Jul 2024 18:51:19 -0300 Subject: [PATCH] feat: add --optimize and --no-optimize option the index reset cli command --- Gemfile.lock | 2 +- lib/esse/cli/index.rb | 1 + spec/esse/cli/index/reset_spec.rb | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 08ebc61..afdf5de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - esse (0.3.2) + esse (0.3.3) multi_json thor (>= 0.19) diff --git a/lib/esse/cli/index.rb b/lib/esse/cli/index.rb index e773249..5a44796 100644 --- a/lib/esse/cli/index.rb +++ b/lib/esse/cli/index.rb @@ -16,6 +16,7 @@ class Index < Base DESC option :suffix, type: :string, default: nil, aliases: '-s', desc: 'Suffix to append to index name' option :import, type: :boolean, default: true, desc: 'Import documents before point alias to the new index' + option :optimize, type: :boolean, default: true, desc: 'Optimize index before import documents by disabling refresh_interval and setting number_of_replicas to 0' def reset(*index_classes) require_relative 'index/reset' Reset.new(indices: index_classes, **options.to_h.transform_keys(&:to_sym)).run diff --git a/spec/esse/cli/index/reset_spec.rb b/spec/esse/cli/index/reset_spec.rb index 88c1ffc..09d9030 100644 --- a/spec/esse/cli/index/reset_spec.rb +++ b/spec/esse/cli/index/reset_spec.rb @@ -35,7 +35,7 @@ end specify do - expect(CountiesIndex).to receive(:reset_index).with(suffix: 'foo', import: true).and_return(true) + expect(CountiesIndex).to receive(:reset_index).with(suffix: 'foo', import: true, optimize: true).and_return(true) cli_exec(%w[index reset CountiesIndex --suffix=foo]) end @@ -50,6 +50,11 @@ expect(CountiesIndex).to receive(:reset_index).and_return(true) cli_exec(%w[index reset all]) end + + specify do + expect(CountiesIndex).to receive(:reset_index).with(import: true, optimize: false).and_return(true) + cli_exec(%w[index reset CountiesIndex --no-optimize]) + end end end end