From 32c65d5a1346b41facc3fed41a40307e4fd14b71 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Thu, 6 Nov 2025 14:20:59 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`conditi?= =?UTF-8?q?onal=5Findexing=5Fwith=5Fenqueue`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @whitemerry. * https://github.com/meilisearch/meilisearch-rails/pull/427#issuecomment-3497481177 The following files were modified: * `lib/meilisearch-rails.rb` --- lib/meilisearch-rails.rb | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/meilisearch-rails.rb b/lib/meilisearch-rails.rb index 3fb47b7..8a87e9b 100644 --- a/lib/meilisearch-rails.rb +++ b/lib/meilisearch-rails.rb @@ -943,6 +943,10 @@ def ms_remove_from_index!(synchronous = false) self.class.ms_remove_from_index!(self, synchronous || ms_synchronous?) end + ## + # Enqueues removal of the record from Meilisearch when an enqueue handler is configured; otherwise performs removal immediately. + # If an enqueue handler is configured and indexing is not disabled, invokes the handler with the record and `true` (requesting removal). If no handler is configured, calls ms_remove_from_index! with the provided synchronous preference or the record's synchronous setting. + # @param [Boolean] synchronous - If `true`, prefer synchronous removal when performing the operation immediately. def ms_enqueue_remove_from_index!(synchronous) if meilisearch_options[:enqueue] unless self.class.send(:ms_indexing_disabled?, meilisearch_options) @@ -953,15 +957,29 @@ def ms_enqueue_remove_from_index!(synchronous) end end + ## + # Enqueues or performs indexing or removal for the current record according to the model's Meilisearch configuration. + # If the record is indexable, this will enqueue an index job when an enqueue handler is configured, otherwise it indexes immediately. + # If the record is not indexable but conditional indexing is enabled, this will enqueue a removal job when an enqueue handler is configured, otherwise it removes the record from the index. + # When using an enqueue handler, the method checks the model's indexing-disabled condition and skips enqueuing if indexing is disabled. + # @param [Boolean] synchronous - When performed immediately (no enqueue handler) controls whether the index/remove operation runs synchronously. def ms_enqueue_index!(synchronous) - return unless Utilities.indexable?(self, meilisearch_options) - - if meilisearch_options[:enqueue] - unless self.class.send(:ms_indexing_disabled?, meilisearch_options) - meilisearch_options[:enqueue].call(self, false) + if Utilities.indexable?(self, meilisearch_options) + if meilisearch_options[:enqueue] + unless self.class.send(:ms_indexing_disabled?, meilisearch_options) + meilisearch_options[:enqueue].call(self, false) + end + else + ms_index!(synchronous) + end + elsif self.class.send(:ms_conditional_index?, meilisearch_options) + if meilisearch_options[:enqueue] + unless self.class.send(:ms_indexing_disabled?, meilisearch_options) + meilisearch_options[:enqueue].call(self, true) + end + else + ms_remove_from_index!(synchronous) end - else - ms_index!(synchronous) end end @@ -1005,4 +1023,4 @@ def ms_perform_index_tasks end end end -end +end \ No newline at end of file