From 2eeff144925d92e6410a4aa2efbed3e0aef24b48 Mon Sep 17 00:00:00 2001 From: Robertas Godelis Date: Thu, 21 Dec 2017 20:31:20 +0200 Subject: [PATCH] Avoid Elasticsearch index updates when passing empty reflections --- lib/chewy/type/import.rb | 1 + spec/chewy/type/import_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/chewy/type/import.rb b/lib/chewy/type/import.rb index 50fdd6f8c..43099dcf9 100644 --- a/lib/chewy/type/import.rb +++ b/lib/chewy/type/import.rb @@ -126,6 +126,7 @@ def compose(object, crutches = nil, fields: []) private def import_routine(*args) + return if args.first.blank? && !args.first.nil? routine = Routine.new(self, args.extract_options!) routine.create_indexes! diff --git a/spec/chewy/type/import_spec.rb b/spec/chewy/type/import_spec.rb index 4784fa035..30fe14ba9 100644 --- a/spec/chewy/type/import_spec.rb +++ b/spec/chewy/type/import_spec.rb @@ -40,6 +40,12 @@ def subscribe_notification CitiesIndex::City.import(dummy_city) end + specify 'lazy without objects' do + expect(CitiesIndex).not_to receive(:exists?) + expect(CitiesIndex).not_to receive(:create!) + CitiesIndex::City.import([]) + end + context 'skip' do before do # To avoid flaky issues when previous specs were run