Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Ensure index exists before indexing the first product (#13862)
Damian Legawiec5b6ab8aa59f4
diff --git a/spree/core/app/models/spree/search_provider/meilisearch.rb b/spree/core/app/models/spree/search_provider/meilisearch.rbindex ead65a396e..be5c4a2d92 100644--- a/spree/core/app/models/spree/search_provider/meilisearch.rb+++ b/spree/core/app/models/spree/search_provider/meilisearch.rb@@ -124,6 +124,7 @@ module Spreeenddef index(product)+ ensure_index_settings_once!documents = presenter_class.new(product, store).callclient.index(index_name).add_documents(documents, 'id')end@@ -178,6 +179,16 @@ module Spreetasks << index.update_sortable_attributes(sortable_attributes)tasks << index.update_searchable_attributes(searchable_attributes)tasks.each { |task| task&.await }+ @index_settings_configured = true+ end++ # Lightweight guard — configures index settings once per provider instance.+ # Meilisearch settings updates are idempotent, so repeated calls are safe+ # but we avoid the overhead by memoizing.+ def ensure_index_settings_once!+ return if @index_settings_configured++ ensure_index_settings!endprivatediff --git a/spree/core/spec/models/spree/search_provider/meilisearch_spec.rb b/spree/core/spec/models/spree/search_provider/meilisearch_spec.rbindex ff74197695..73567a60be 100644--- a/spree/core/spec/models/spree/search_provider/meilisearch_spec.rb+++ b/spree/core/spec/models/spree/search_provider/meilisearch_spec.rb@@ -14,6 +14,9 @@ module Spreebefore doallow(::Meilisearch::Client).to receive(:new).and_return(mock_client)allow(mock_client).to receive(:index).and_return(mock_index)+ allow(mock_index).to receive(:update_filterable_attributes)+ allow(mock_index).to receive(:update_sortable_attributes)+ allow(mock_index).to receive(:update_searchable_attributes)enddescribe '#search_and_filter' do@@ -195,12 +198,6 @@ module Spreeenddescribe '#reindex' do- before do- allow(mock_index).to receive(:update_filterable_attributes)- allow(mock_index).to receive(:update_sortable_attributes)- allow(mock_index).to receive(:update_searchable_attributes)- end-it 'configures index settings' doexpect(mock_index).to receive(:update_filterable_attributes)expect(mock_index).to receive(:update_sortable_attributes)