Skip to content

AutoIndexing does not work well with transactions #353

@Gasparila

Description

@Gasparila

• 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 ||=

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions