Class: Chewy::Journal
- Inherits:
-
Object
- Object
- Chewy::Journal
- Defined in:
- lib/chewy/journal.rb
Overview
A class to perform journal-related actions for the specified indexes/types.
Instance Method Summary collapse
-
#apply(since_time, fetch_limit: 10, **import_options) ⇒ Integer
Applies all changes that were done since the specified time to the specified indexes.
-
#clean(until_time = nil, delete_by_query_options: {}) ⇒ Hash
Cleans journal for the specified indexes/types.
-
#initialize(*only) ⇒ Journal
constructor
A new instance of Journal.
Constructor Details
#initialize(*only) ⇒ Journal
Returns a new instance of Journal.
11 12 13 |
# File 'lib/chewy/journal.rb', line 11 def initialize(*only) @only = only end |
Instance Method Details
#apply(since_time, fetch_limit: 10, **import_options) ⇒ Integer
Applies all changes that were done since the specified time to the specified indexes.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/chewy/journal.rb', line 21 def apply(since_time, fetch_limit: 10, **) stage = 1 since_time -= 1 count = 0 total_count = entries(since_time, fetch_limit).total_count while count < total_count entries = entries(since_time, fetch_limit).to_a.presence or break count += entries.size groups = reference_groups(entries) ActiveSupport::Notifications.instrument 'apply_journal.chewy', stage: stage, groups: groups groups.each do |index, references| index.import(references, .merge(journal: false)) end stage += 1 since_time = entries.map(&:created_at).max end count end |
#clean(until_time = nil, delete_by_query_options: {}) ⇒ Hash
Cleans journal for the specified indexes/types.
46 47 48 49 50 51 52 |
# File 'lib/chewy/journal.rb', line 46 def clean(until_time = nil, delete_by_query_options: {}) Chewy::Stash::Journal.clean( until_time, only: @only, delete_by_query_options: .merge(refresh: false) ) end |