Skip to content

Commit eca701e

Browse files
authored
Remove checks on conditions in the 'ms_must_reindex?' method
This commit removes the checks on the meilisearch conditions options `:if` and `:unless` in the `ms_must_reindex?` method as they are incorrectly used. ## Low level reason [Indeed the README documents an example on how to avoid reindexing when an `if:` condition is defined (e.g. `if: :published?`)](https://github.com/meilisearch/meilisearch-rails/tree/main?tab=readme-ov-file#conditional-indexing). However the documented way doesn't work: Indeed, one would need to define a method `#will_save_change_to_published??` (note the two question marks) to be able to prevent reindexing. However ruby doesn't allow such a method name (with double trailing question marks). ## Higher level reason In a high level vision, the `if:` and `unless:` conditions are used as “constraints” when the lib will try to index a resource in many different places of the code by executing `Utilities.indexable?(...)` before trying to index, those those conditions are sufficient to “enable” or “disable” the indexation of the lib, no matter what attributes change on the record. Why would the “must_reindex” logic try to check those conditions? I admit I didn't understand and believe this code is obsolete. What do you folks think?
1 parent 16e4d4b commit eca701e

File tree

1 file changed

+0
-13
lines changed

1 file changed

+0
-13
lines changed

lib/meilisearch-rails.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,6 @@ def ms_must_reindex?(document)
765765
return true if ms_attribute_changed?(document, k)
766766
# return true if !document.respond_to?(changed_method) || document.send(changed_method)
767767
end
768-
[options[:if], options[:unless]].each do |condition|
769-
case condition
770-
when nil
771-
return false
772-
when String, Symbol
773-
return true if ms_attribute_changed?(document, condition)
774-
else
775-
# if the :if, :unless condition is a anything else,
776-
# we have no idea whether we should reindex or not
777-
# let's always reindex then
778-
return true
779-
end
780-
end
781768
end
782769

783770
# By default, we don't reindex

0 commit comments

Comments
 (0)