class Chewy::Stash::Journal

Public Class Methods

clean(until_time = nil, only: [], delete_by_query_options: {}) click to toggle source

Cleans up all the journal entries until the specified time. If nothing is specified - cleans up everything.

@param until_time [Time, DateTime] Clean everything before that date @param only [Chewy::Index, Array<Chewy::Index>] indexes to clean up journal entries for

# 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: []) click to toggle source

Loads all entries since the specified time.

@param since_time [Time, DateTime] a timestamp from which we load a journal @param only [Chewy::Index, Array<Chewy::Index>] journal entries related to these indices will be loaded only

# 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) click to toggle source

Selects all the journal entries for the specified indices.

@param indices [Chewy::Index, Array<Chewy::Index>]

# 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

Public Instance Methods

references() click to toggle source
# 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