searchkick 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2afa6ea99c2995b003f51cbe409392097fdfa8e
4
- data.tar.gz: dc2e4add51195454636f94db1ae6417c2a8933bb
3
+ metadata.gz: 74cd357aadff8dc7f80b5db94f74dde7940abcd8
4
+ data.tar.gz: ae9c5f086a639fbb18e0848a862231f188ee7624
5
5
  SHA512:
6
- metadata.gz: 1895d905c2b916de3e5e5fb5640d8132318f0dccffa553cfd6770d1c38d84bcd5dc9c92d1749711fa16f0bfdf677962318a5ec50e366f91e0dd1324121bf169f
7
- data.tar.gz: 8c9bc21cf09a320ee676d2307f7ebbdbf1cc2f2dce37633e799f6282ee2f3f1d8e5ba0af1696c23c2271f401ca1173b4803779f6f50f43cd8674db15c7483620
6
+ metadata.gz: 22c8007b1672a5ca1d6def91d812509f50fc795b0744817f8af52feaa024c569b6f993f41b138f47c2aa5d42a7709faa2e6a51f1ff3a5005ff0c8e084ae1a4e9
7
+ data.tar.gz: ce18c6e5766bfc8a203c1a6ebe77f9d717b7a88c6ce361858ad15fa3049a4722cb5dcc23bc41f0e3d3be9e12f34a47d70a6783b458b2fe9701cb5d673376711f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.5.2
2
+
3
+ - Use after_commit hook for ActiveRecord to prevent data inconsistencies
4
+
1
5
  ## 0.5.1
2
6
 
3
7
  - Replaced stop words with common terms query
data/README.md CHANGED
@@ -657,25 +657,18 @@ class Product < ActiveRecord::Base
657
657
  end
658
658
  ```
659
659
 
660
- Reindex conditionally
660
+ Asynchronous reindexing
661
661
 
662
662
  ```ruby
663
663
  class Product < ActiveRecord::Base
664
664
  searchkick callbacks: false
665
665
 
666
666
  # add the callbacks manually
667
- after_save :reindex, if: proc{|model| model.name_changed? } # use your own condition
668
- after_destroy :reindex
669
- end
670
- ```
671
667
 
672
- Asynchronous reindexing
668
+ # ActiveRecord - one callback
669
+ after_commit :reindex_async
673
670
 
674
- ```ruby
675
- class Product < ActiveRecord::Base
676
- searchkick callbacks: false
677
-
678
- # add the callbacks manually
671
+ # Mongoid - two callbacks
679
672
  after_save :reindex_async
680
673
  after_destroy :reindex_async
681
674
 
@@ -686,6 +679,20 @@ class Product < ActiveRecord::Base
686
679
  end
687
680
  ```
688
681
 
682
+ Reindex conditionally
683
+
684
+ **Note:** With ActiveRecord, use this feature with caution - [transaction rollbacks can cause data inconstencies](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md#custom-callbacks)
685
+
686
+ ```ruby
687
+ class Product < ActiveRecord::Base
688
+ searchkick callbacks: false
689
+
690
+ # add the callbacks manually
691
+ after_save :reindex, if: proc{|model| model.name_changed? } # use your own condition
692
+ after_destroy :reindex
693
+ end
694
+ ```
695
+
689
696
  Reindex all models (Rails only)
690
697
 
691
698
  ```sh
@@ -19,8 +19,12 @@ module Searchkick
19
19
  extend Searchkick::Reindex
20
20
  include Searchkick::Similar
21
21
 
22
- after_save :reindex, if: proc { self.class.search_callbacks? }
23
- after_destroy :reindex, if: proc { self.class.search_callbacks? }
22
+ if respond_to?(:after_commit)
23
+ after_commit :reindex, if: proc{ self.class.search_callbacks? }
24
+ else
25
+ after_save :reindex, if: proc{ self.class.search_callbacks? }
26
+ after_destroy :reindex, if: proc{ self.class.search_callbacks? }
27
+ end
24
28
 
25
29
  def self.enable_search_callbacks
26
30
  class_variable_set :@@searchkick_callbacks, true
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
data/test/index_test.rb CHANGED
@@ -32,4 +32,17 @@ class TestIndex < Minitest::Unit::TestCase
32
32
  assert_equal ["Dollar Tree"], Store.search(query: {match: {name: "Dollar Tree"}}).map(&:name)
33
33
  end
34
34
 
35
+ if defined?(ActiveRecord)
36
+
37
+ def test_transaction
38
+ Product.transaction do
39
+ store_names ["Product A"]
40
+ raise ActiveRecord::Rollback
41
+ end
42
+
43
+ assert_search "product", []
44
+ end
45
+
46
+ end
47
+
35
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane