esse-active_record 0.3.5 → 0.3.6

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
  SHA256:
3
- metadata.gz: edf541425801e7e18e816e6a0169c021f52017829ada9643f959452ba207a658
4
- data.tar.gz: 8cbc35bd232d9c6fde1cc6ef79aba08feffd00db04dfd6238cf60f4058457bd5
3
+ metadata.gz: d6ec661a171ddf9df565e1da2c3ca67bc34fc18ec957e47867e50b043ce0ee44
4
+ data.tar.gz: 29e7acc6af3e77bbe52dde14038de3ad82532964dbc7293cdc77f2a3ae4764a3
5
5
  SHA512:
6
- metadata.gz: 3125eb0d88c23be59bdb5a889005357833b50cde303be94ed9e2fce2fc008bb59e2c636d7c08f14b9f028a84aad6f35d43151824669210916067dfa2e42f6991
7
- data.tar.gz: 217f00f691e17cc13402a63e799220a94807194205fd1439ebe426f1e36bcef73511793cd71a8a3931c0b1e975cb7b3fa2ada1b92eac8de8151f2f70016a5168
6
+ metadata.gz: cc76722e48a2ea6e002b08dd9f29b53bed75cf4f857254dde166bfc30090fc16482e3b70fe47dbc7409e970dfb5d47b5dcefcc5bf413d56382f5e9a909e98837
7
+ data.tar.gz: 76dcbec4c950921945faa13785273e523d82644d3757d3b27ee91f352f155371b218f9f1ff40b079cd04ad722acedf8c873b01532dc9143249b0616636b98b0e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- esse-active_record (0.3.5)
4
+ esse-active_record (0.3.6)
5
5
  activerecord (>= 4.2, < 8)
6
6
  esse (>= 0.3.0)
7
7
 
data/README.md CHANGED
@@ -210,6 +210,35 @@ User.without_indexing(AccountsIndex) do
210
210
  end
211
211
  ```
212
212
 
213
+ ### Asynchronous Indexing
214
+
215
+ If you are using a background job processor like Sidekiq or Faktory, you may be interested in indexing documents asynchronously. For this, you can use the [esse-async_indexing](https://github.com/marcosgz/esse-async_indexing) gem.
216
+
217
+ Add the `esse-async_indexing` gem to your Gemfile and require the `esse/async_indexing/active_record` file in your application initialization. Make sure to setup the gem configurationg according to the [esse-async_indexing documentation](https://github.com/marcosgz/esse-async_indexing).
218
+
219
+
220
+ ```ruby
221
+ require 'esse/async_indexing/active_record'
222
+ ```
223
+
224
+ Then, you can use the `async_index_callback` or `async_update_lazy_attribute_callback` methods to push the indexing job to the background job processor.
225
+
226
+ ```diff
227
+ class City < ApplicationRecord
228
+ include Esse::ActiveRecord::Model
229
+ - include Esse::ActiveRecord::Model
230
+ + include Esse::AsyncIndexing::ActiveRecord::Model
231
+
232
+ belongs_to :state, optional: true
233
+
234
+
235
+ async_indexing_callback('geos_index:city') { id }
236
+ - index_callback('geos_index:city') { id }
237
+ - update_lazy_attribute_callback('geos_index:state', 'cities_count', if: :state_id?) { state_id }
238
+ + async_index_callback('geos_index:city', service_name: :sidekiq) { id }
239
+ + async_update_lazy_attribute_callback('geos_index:state', 'cities_count', if: :state_id?, service_name: :sidekiq) { state_id }
240
+ end
241
+ ```
213
242
 
214
243
  ## Development
215
244
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- esse-active_record (0.3.5)
4
+ esse-active_record (0.3.6)
5
5
  activerecord (>= 4.2, < 8)
6
6
  esse (>= 0.3.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- esse-active_record (0.3.5)
4
+ esse-active_record (0.3.6)
5
5
  activerecord (>= 4.2, < 8)
6
6
  esse (>= 0.3.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- esse-active_record (0.3.5)
4
+ esse-active_record (0.3.6)
5
5
  activerecord (>= 4.2, < 8)
6
6
  esse (>= 0.3.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- esse-active_record (0.3.5)
4
+ esse-active_record (0.3.6)
5
5
  activerecord (>= 4.2, < 8)
6
6
  esse (>= 0.3.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- esse-active_record (0.3.5)
4
+ esse-active_record (0.3.6)
5
5
  activerecord (>= 4.2, < 8)
6
6
  esse (>= 0.3.0)
7
7
 
@@ -3,13 +3,6 @@
3
3
  module Esse::ActiveRecord
4
4
  module Callbacks
5
5
  class IndexingOnUpdate < Callback
6
- attr_reader :update_with
7
-
8
- def initialize(with: :index, **kwargs, &block)
9
- @update_with = with
10
- super(**kwargs, &block)
11
- end
12
-
13
6
  def call(model)
14
7
  record = block_result || model
15
8
 
@@ -43,7 +36,7 @@ module Esse::ActiveRecord
43
36
  def update_document(document)
44
37
  return if document.ignore_on_index?
45
38
 
46
- if update_with == :update
39
+ if @with == :update || (@with.nil? && repo.lazy_document_attributes.any?)
47
40
  begin
48
41
  repo.index.update(document, **options)
49
42
  rescue Esse::Transport::NotFoundError
@@ -5,8 +5,9 @@ module Esse
5
5
  class Callback
6
6
  attr_reader :repo, :options, :block_result
7
7
 
8
- def initialize(repo:, block_result: nil, **kwargs)
8
+ def initialize(repo:, block_result: nil, with: nil, **kwargs)
9
9
  @repo = repo
10
+ @with = with
10
11
  @options = kwargs
11
12
  @block_result = block_result
12
13
  end
@@ -90,7 +90,7 @@ module Esse
90
90
  end
91
91
 
92
92
  def count
93
- dataset.except(:includes, :preload, :eager_load).count
93
+ dataset.except(:includes, :preload, :eager_load, :group, :order, :limit, :offset).count
94
94
  end
95
95
  alias_method :size, :count
96
96
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Esse
4
4
  module ActiveRecord
5
- VERSION = '0.3.5'
5
+ VERSION = '0.3.6'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esse-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos G. Zimmermann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-29 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: esse