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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +29 -0
- data/ci/Gemfile.rails-5.2.lock +1 -1
- data/ci/Gemfile.rails-6.0.lock +1 -1
- data/ci/Gemfile.rails-6.1.lock +1 -1
- data/ci/Gemfile.rails-7.0.lock +1 -1
- data/ci/Gemfile.rails-7.1.lock +1 -1
- data/lib/esse/active_record/callbacks/indexing_on_update.rb +1 -8
- data/lib/esse/active_record/callbacks.rb +2 -1
- data/lib/esse/active_record/collection.rb +1 -1
- data/lib/esse/active_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6ec661a171ddf9df565e1da2c3ca67bc34fc18ec957e47867e50b043ce0ee44
|
4
|
+
data.tar.gz: 29e7acc6af3e77bbe52dde14038de3ad82532964dbc7293cdc77f2a3ae4764a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc76722e48a2ea6e002b08dd9f29b53bed75cf4f857254dde166bfc30090fc16482e3b70fe47dbc7409e970dfb5d47b5dcefcc5bf413d56382f5e9a909e98837
|
7
|
+
data.tar.gz: 76dcbec4c950921945faa13785273e523d82644d3757d3b27ee91f352f155371b218f9f1ff40b079cd04ad722acedf8c873b01532dc9143249b0616636b98b0e
|
data/Gemfile.lock
CHANGED
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
|
|
data/ci/Gemfile.rails-5.2.lock
CHANGED
data/ci/Gemfile.rails-6.0.lock
CHANGED
data/ci/Gemfile.rails-6.1.lock
CHANGED
data/ci/Gemfile.rails-7.0.lock
CHANGED
data/ci/Gemfile.rails-7.1.lock
CHANGED
@@ -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
|
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
|
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.
|
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-
|
11
|
+
date: 2024-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: esse
|