Skip to content

Commit 1b1a203

Browse files
committed
Fix #352 and #353
Fix breaking change introduced in #352 According to the [documentation](https://github.com/algolia/algoliasearch-rails/blob/master/lib/README.md#630), using custom attributes without a custom `_changed?` method will always cause changes to push to the API. This behavior was lost in #338 Fix unexpected behavior during transactions #353 `@algolia_must_reindex` is reset in every validate call. This means that a record that is updated multiple times in a transaction will only be indexed if the final update marks as must reindex. Update the code so that once `@algolia_must_reindex` is marked as `true`, it remains true until explicitly unset in `algolia_perform_index_tasks`
1 parent 360e47d commit 1b1a203

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/algoliasearch-rails.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ def algolia_attribute_changed?(object, attr_name)
953953
return object.send("will_save_change_to_#{attr_name}?")
954954
end
955955

956-
# Nil means we don't know if the attribute has changed
957-
nil
956+
# We don't know if the attribute has changed, so conservatively assume it has
957+
true
958958
end
959959

960960
def automatic_changed_method?(object, method_name)
@@ -1018,7 +1018,9 @@ def algolia_mark_for_auto_indexing
10181018
end
10191019

10201020
def algolia_mark_must_reindex
1021-
@algolia_must_reindex =
1021+
# algolia_must_reindex flag is reset after every commit as part. If we must reindex at any point in
1022+
# a stransaction, keep flag set until it is explicitly unset
1023+
@algolia_must_reindex ||=
10221024
if defined?(::Sequel) && is_a?(Sequel::Model)
10231025
new? || self.class.algolia_must_reindex?(self)
10241026
else

0 commit comments

Comments
 (0)