algoliasearch-rails 1.13.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba7c93249fd23c8c5d422db7273d3250c76d6e13
4
- data.tar.gz: 37d32353f83ae66f722b13895c75d22783241b3b
3
+ metadata.gz: 5bf2c250427bfa73975a60a1b95c44862b8b3bf8
4
+ data.tar.gz: 394a6343e354ab6d06d52a591dfdf180bbfb71d1
5
5
  SHA512:
6
- metadata.gz: 8ee2a2189fba6910b8d0ddfbc422c6aa81fe5e1366efe8e130cbb1986fac59223d30d3894199c70e77ef79b54aa325dd021c5d7b51d727350265f7ef6b311fdc
7
- data.tar.gz: 5a72387eca06e26c0623e6cefa27f616d85966d0605dc68746932dfa1bf0014b72c9e0e9b86f05c80b41171e8ca74be506be4897c2082b466fc7df5c68ec1dfe
6
+ metadata.gz: 03e82327f0b465766890e0d2bd67b4a39cd5358d54abddfc4d98b74f324700eabfc1f154bf56a34daa4ffbacf80c711412c3c52a4b0d89241d4eff608892e962
7
+ data.tar.gz: 7ef544f736f80b80a428ae41070f958d67c1283412056b7476750e292a5862da51fa6f9daf1d5422c95554c4837f6b69c1bcc0f7dc4aa56f9ff450e22bce912b
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  CHANGELOG
2
2
 
3
+ 2015-07-20 1.13.1
4
+
5
+ * Use `after_commit` instead of `after_save` to ensure we index once in the DB
6
+
3
7
  2015-06-21 1.13.0
4
8
 
5
9
  * Ability to use a background queue to handle all automatic indexing operations
data/README.md CHANGED
@@ -149,7 +149,7 @@ The JS API client is part of the gem, just require ```algolia/v3/algoliasearch.m
149
149
  Then in your JavaScript code you can do:
150
150
 
151
151
  ```js
152
- var client = new AlgoliaSearch('ApplicationID', 'Search-Only-API-Key');
152
+ var client = algoliasearch(ApplicationID, Search-Only-API-Key);
153
153
  var index = client.initIndex('YourIndexName');
154
154
  index.search('something', function(success, hits) {
155
155
  console.log(success, hits)
@@ -240,13 +240,14 @@ class Contact < ActiveRecord::Base
240
240
  end
241
241
 
242
242
  def self.trigger_sidekiq_worker(record, remove)
243
- MySidekiqWorker.perform_async(record, remove)
243
+ MySidekiqWorker.perform_async(record.id, remove)
244
244
  end
245
245
  end
246
246
 
247
247
  class MySidekiqWorker
248
- def perform(record, remove)
249
- remove ? record.remove_from_index! : record.index!
248
+ def perform(id, remove)
249
+ c = Contact.find(id)
250
+ remove ? c.remove_from_index! : c.index!
250
251
  end
251
252
  end
252
253
  ```
@@ -607,6 +608,15 @@ To clear an index, use the <code>clear_index!</code> class method:
607
608
  Contact.clear_index!
608
609
  ```
609
610
 
611
+ #### Using the underlying index
612
+
613
+ You can access the underlying `index` object by calling the `index` class method:
614
+
615
+ ```ruby
616
+ index = Contact.index
617
+ # index.get_settings, index.partial_update_object, ...
618
+ ```
619
+
610
620
  Master/slave
611
621
  ---------
612
622
 
@@ -858,7 +868,7 @@ Turns any ```input[type="text"]``` element into a typeahead, for example:
858
868
  Caveats
859
869
  --------
860
870
 
861
- This gem makes intensive use of Rails' callbacks to trigger the indexing tasks. If you're using methods bypassing ```after_validation```, ```before_save``` or ```after_save``` callbacks, it will not index your changes. For example: ```update_attribute``` doesn't perform validations checks, to perform validations when updating use ```update_attributes```.
871
+ This gem makes intensive use of Rails' callbacks to trigger the indexing tasks. If you're using methods bypassing ```after_validation```, ```before_save``` or ```after_commit``` callbacks, it will not index your changes. For example: ```update_attribute``` doesn't perform validations checks, to perform validations when updating use ```update_attributes```.
862
872
 
863
873
  Timeouts
864
874
  ---------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.13.0
1
+ 1.13.1
@@ -337,7 +337,7 @@ module AlgoliaSearch
337
337
  class_eval do
338
338
  copy_after_validation = instance_method(:after_validation)
339
339
  copy_before_save = instance_method(:before_save)
340
- copy_after_save = instance_method(:after_save)
340
+ copy_after_commit = instance_method(:after_commit)
341
341
 
342
342
  define_method(:after_validation) do |*args|
343
343
  super(*args)
@@ -351,16 +351,20 @@ module AlgoliaSearch
351
351
  super(*args)
352
352
  end
353
353
 
354
- define_method(:after_save) do |*args|
354
+ define_method(:after_commit) do |*args|
355
355
  super(*args)
356
- copy_after_save.bind(self).call
356
+ copy_after_commit.bind(self).call
357
357
  algolia_perform_index_tasks
358
358
  end
359
359
  end
360
360
  else
361
361
  after_validation :algolia_mark_must_reindex if respond_to?(:after_validation)
362
362
  before_save :algolia_mark_for_auto_indexing if respond_to?(:before_save)
363
- after_save :algolia_perform_index_tasks if respond_to?(:after_save)
363
+ if respond_to?(:after_commit)
364
+ after_commit :algolia_perform_index_tasks
365
+ elsif respond_to?(:after_save)
366
+ after_save :algolia_perform_index_tasks
367
+ end
364
368
  end
365
369
  end
366
370
  unless options[:auto_remove] == false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-21 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json