Skip to content

AutoIndexing does not work well with transactions #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Gasparila opened this issue May 10, 2019 · 1 comment
Closed

AutoIndexing does not work well with transactions #353

Gasparila opened this issue May 10, 2019 · 1 comment

Comments

@Gasparila
Copy link
Contributor

• Rails version: 5.1.6
• Algolia Rails integration version: 1.22

Description

@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

Steps To Reproduce

class AnyModel < ActiveRecord::Base
  include AlgoliaSearch
  
  algoliasearch do
    attribute(:name)
  end
end

# after_commit will have  @algolia_must_reindex = false
AnyModel.transaction do
  instance_of_model.update!(name: "foobar")
  instance_of_model.update!(unrelated_column: 23)
end

Suggested Fix

Change first line of def algolia_mark_must_reindex to

@algolia_must_reindex ||=
Gasparila added a commit to flexport/algoliasearch-rails that referenced this issue May 11, 2019
Fix breaking change introduced in algolia#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 algolia#338

Fix unexpected behavior during transactions algolia#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`
Gasparila added a commit to flexport/algoliasearch-rails that referenced this issue May 11, 2019
Fix breaking change introduced in algolia#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 algolia#338

Fix unexpected behavior during transactions algolia#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`
Gasparila added a commit to flexport/algoliasearch-rails that referenced this issue May 13, 2019
@julienbourdeau
Copy link
Contributor

Fixed by #354

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants