class Longleaf::IndexManager

Manager configures and provides access to a metadata index if one is specified

Public Class Methods

new(config, app_config_manager) click to toggle source

@param config [Hash] The system configuration as a hash @param app_config_manager [ApplicationConfigManager] the application config

# File lib/longleaf/indexing/index_manager.rb, line 12
def initialize(config, app_config_manager)
  @config = config
  @app_config_manager = app_config_manager
  init_index_driver if @config&.key?(SYS_FIELDS::MD_INDEX)
end

Public Instance Methods

clear_index(older_than = nil) click to toggle source
# File lib/longleaf/indexing/index_manager.rb, line 36
def clear_index(older_than = nil)
  @index_driver.clear_index(older_than)
end
each_registered_path(file_selector, older_than: nil, &block) click to toggle source
# File lib/longleaf/indexing/index_manager.rb, line 71
def each_registered_path(file_selector, older_than: nil, &block)
  @index_driver.each_registered_path(file_selector, older_than: older_than, &block)
end
index(file_rec) click to toggle source

Index the provided file_rec and its metadata

@param file_rec [FileRecord] file record to index

# File lib/longleaf/indexing/index_manager.rb, line 26
def index(file_rec)
  @index_driver.index(file_rec)
end
index_stale?() click to toggle source

@return true if the index should be reindexed

# File lib/longleaf/indexing/index_manager.rb, line 41
def index_stale?
  @index_driver.is_stale?
end
paths_with_stale_services(file_selector, stale_datetime) click to toggle source

Retrieves a set of which have one or more services which need to run.

@param file_selector [FileSelector] selector for paths to search for files @param stale_datetime [DateTime] find file_paths with services needing to be run before this value @return [Array] array of file paths that need one or more services run, in ascending order by

timestamp.
# File lib/longleaf/indexing/index_manager.rb, line 60
def paths_with_stale_services(file_selector, stale_datetime)
  @index_driver.paths_with_stale_services(file_selector, stale_datetime)
end
registered_paths(file_selector) click to toggle source

Retrieves a page of paths for registered files. @param file_selector [FileSelector] selector for what paths to search for files @return [Array] array of file paths that are registered

# File lib/longleaf/indexing/index_manager.rb, line 67
def registered_paths(file_selector)
  @index_driver.registered_paths(file_selector)
end
remove(remove_me) click to toggle source

Remove an entry from the index @param remove_me The record to remove from the index

# File lib/longleaf/indexing/index_manager.rb, line 32
def remove(remove_me)
  @index_driver.remove(remove_me)
end
setup_index() click to toggle source

Setup initial structure of index implementation

# File lib/longleaf/indexing/index_manager.rb, line 46
def setup_index
  @index_driver.setup_index
end
update_index_state() click to toggle source
# File lib/longleaf/indexing/index_manager.rb, line 50
def update_index_state
  @index_driver.update_index_state
end
using_index?() click to toggle source

@return true if the system is configured to use a metadata index

# File lib/longleaf/indexing/index_manager.rb, line 19
def using_index?
  !@index_driver.nil?
end

Private Instance Methods

init_index_driver() click to toggle source
# File lib/longleaf/indexing/index_manager.rb, line 76
def init_index_driver
  index_conf = @config[SYS_FIELDS::MD_INDEX]
  adapter = index_conf[SYS_FIELDS::MD_INDEX_ADAPTER]&.downcase

  raise ConfigurationError.new('Must specify an adapter for the metadata index') if adapter.nil?

  adapter = adapter.to_sym

  case adapter
  when :postgres, :mysql, :mysql2, :sqlite, :amalgalite
    page_size = index_conf[SYS_FIELDS::MD_INDEX_PAGE_SIZE]&.to_int

    connection = index_conf[SYS_FIELDS::MD_INDEX_CONNECTION]
    raise ConfigurationError.new("Must specify connection details for index adapter of type '#{adapter}'") if connection.nil?

    require 'longleaf/indexing/sequel_index_driver'
    @index_driver = SequelIndexDriver.new(@app_config_manager,
        adapter,
        connection,
        page_size: page_size)
  else
    raise ConfigurationError.new("Unknown index adapter '#{adapter}' specified.") if adapter.nil?
  end
end