Class: Chewy::Stash::Journal

Inherits:
Index
  • Object
show all
Defined in:
lib/chewy/stash.rb

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

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.

Parameters:

  • until_time (Time, DateTime) (defaults to: nil)

    Clean everything before that date

  • only (Chewy::Index, Array<Chewy::Index>) (defaults to: [])

    indexes to clean up journal entries for



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(**delete_by_query_options)
end

.entries(since_time, only: []) ⇒ Object

Loads all entries since the specified time.

Parameters:

  • since_time (Time, DateTime)

    a timestamp from which we load a journal

  • only (Chewy::Index, Array<Chewy::Index>) (defaults to: [])

    journal entries related to these indices will be loaded only



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.

Parameters:



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chewy/stash.rb', line 42

def self.for(*something)
  something = something.flatten.compact
  indexes = something.flat_map { |s| Chewy.derive_name(s) }
  return none if something.present? && indexes.blank?

  scope = all
  indexes.each do |index|
    scope = scope.or(filter(term: {index_name: index.derivable_name}))
  end
  scope
end

Instance Method Details

#referencesObject



61
62
63
64
65
# File 'lib/chewy/stash.rb', line 61

def references
  @references ||= Array.wrap(@attributes['references']).map do |item|
    JSON.load(Base64.decode64(item)) # rubocop:disable Security/JSONLoad
  end
end