Skip to content

Commit 32c65d5

Browse files
📝 Add docstrings to conditional_indexing_with_enqueue
Docstrings generation was requested by @whitemerry. * #427 (comment) The following files were modified: * `lib/meilisearch-rails.rb`
1 parent 16e4d4b commit 32c65d5

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

lib/meilisearch-rails.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,10 @@ def ms_remove_from_index!(synchronous = false)
943943
self.class.ms_remove_from_index!(self, synchronous || ms_synchronous?)
944944
end
945945

946+
##
947+
# Enqueues removal of the record from Meilisearch when an enqueue handler is configured; otherwise performs removal immediately.
948+
# 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.
949+
# @param [Boolean] synchronous - If `true`, prefer synchronous removal when performing the operation immediately.
946950
def ms_enqueue_remove_from_index!(synchronous)
947951
if meilisearch_options[:enqueue]
948952
unless self.class.send(:ms_indexing_disabled?, meilisearch_options)
@@ -953,15 +957,29 @@ def ms_enqueue_remove_from_index!(synchronous)
953957
end
954958
end
955959

960+
##
961+
# Enqueues or performs indexing or removal for the current record according to the model's Meilisearch configuration.
962+
# If the record is indexable, this will enqueue an index job when an enqueue handler is configured, otherwise it indexes immediately.
963+
# 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.
964+
# When using an enqueue handler, the method checks the model's indexing-disabled condition and skips enqueuing if indexing is disabled.
965+
# @param [Boolean] synchronous - When performed immediately (no enqueue handler) controls whether the index/remove operation runs synchronously.
956966
def ms_enqueue_index!(synchronous)
957-
return unless Utilities.indexable?(self, meilisearch_options)
958-
959-
if meilisearch_options[:enqueue]
960-
unless self.class.send(:ms_indexing_disabled?, meilisearch_options)
961-
meilisearch_options[:enqueue].call(self, false)
967+
if Utilities.indexable?(self, meilisearch_options)
968+
if meilisearch_options[:enqueue]
969+
unless self.class.send(:ms_indexing_disabled?, meilisearch_options)
970+
meilisearch_options[:enqueue].call(self, false)
971+
end
972+
else
973+
ms_index!(synchronous)
974+
end
975+
elsif self.class.send(:ms_conditional_index?, meilisearch_options)
976+
if meilisearch_options[:enqueue]
977+
unless self.class.send(:ms_indexing_disabled?, meilisearch_options)
978+
meilisearch_options[:enqueue].call(self, true)
979+
end
980+
else
981+
ms_remove_from_index!(synchronous)
962982
end
963-
else
964-
ms_index!(synchronous)
965983
end
966984
end
967985

@@ -1005,4 +1023,4 @@ def ms_perform_index_tasks
10051023
end
10061024
end
10071025
end
1008-
end
1026+
end

0 commit comments

Comments
 (0)