Class: Chewy::Stash::Journal
Constant Summary
Constants inherited from Index
Index::IMPORT_OPTIONS_KEYS, Index::STRATEGY_OPTIONS
Constants included from Index::Import
Index::Import::IMPORT_WORKER, Index::Import::LEFTOVERS_WORKER
Class Method Summary collapse
-
.clean(until_time = nil, only: [], delete_by_query_options: {}) ⇒ Object
Cleans up all the journal entries until the specified time.
-
.entries(since_time, only: []) ⇒ Object
Loads all entries since the specified time.
-
.for(*something) ⇒ Object
Selects all the journal entries for the specified indices.
Instance Method Summary collapse
Methods inherited from Index
base_name, default_import_options, derivable_name, index_name, index_scope, mappings_hash, prefix, scopes, settings, settings_hash, specification, specification_hash, strategy_config
Methods included from Index::Wrapper
#==, #initialize, #method_missing, #respond_to_missing?
Methods included from Index::Observe::Helpers
#extract_callback_options!, #update_proc
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chewy::Index::Wrapper
Class Method Details
.clean(until_time = nil, only: [], delete_by_query_options: {}) ⇒ Object
Cleans up all the journal entries until the specified time. If nothing is specified - cleans up everything.
33 34 35 36 37 |
# File 'lib/chewy/stash.rb', line 33 def self.clean(until_time = nil, only: [], delete_by_query_options: {}) scope = self.for(only) scope = scope.filter(range: {created_at: {lte: until_time}}) if until_time scope.delete_all(**) end |
.entries(since_time, only: []) ⇒ Object
Loads all entries since the specified time.
24 25 26 |
# File 'lib/chewy/stash.rb', line 24 def self.entries(since_time, only: []) self.for(only).filter(range: {created_at: {gt: since_time}}).filter.minimum_should_match(1) end |
.for(*something) ⇒ Object
Selects all the journal entries for the specified indices.
Uses a single ‘terms` filter rather than a chain of `bool.should` clauses so the query depth stays constant regardless of how many indices are passed. Avoids hitting the Elasticsearch `indices.query.bool.max_nested_depth` limit (default 30) when cleaning or applying journals across many indices.
48 49 50 51 52 53 54 55 56 |
# File 'lib/chewy/stash.rb', line 48 def self.for(*something) something = something.flatten.compact return all if something.empty? indexes = something.flat_map { |s| Chewy.derive_name(s) } return none if indexes.blank? filter(terms: {index_name: indexes.map(&:derivable_name).uniq}) end |
Instance Method Details
#references ⇒ Object
65 66 67 68 69 |
# File 'lib/chewy/stash.rb', line 65 def references @references ||= Array.wrap(@attributes['references']).map do |item| JSON.load(Base64.decode64(item)) # rubocop:disable Security/JSONLoad end end |