# In development environments we don't want to depend on Rummager unless
# explicitly told to do so
unless Rails.env.development?
  update_search = true
else
  update_search = ENV['UPDATE_SEARCH'].present?
end

if update_search
  Rails.logger.info "Registering search observer for artefacts"
  Panopticon::Application.config.mongoid.observers << :update_search_observer
else
  Rails.logger.info "In development/test mode: not registering search observer"
end

# In development environments we don't want to depend on Rummager unless
# explicitly told to do so
unless Rails.env.development?
  update_search = true
else
  update_search = ENV['UPDATE_SEARCH'].present?
end

if update_search
  Rails.logger.info "Registering search observer for artefacts"
  # Use to_prepare so this gets reloaded with the app when in development
  # In production, it will only be called once
  ActionDispatch::Callbacks.to_prepare do
    Panopticon::Application.config.mongoid.observers << :update_search_observer
  end
else
  Rails.logger.info "In development/test mode: not registering search observer"
end

Fix the observer initialiser for development mode.
Fix the observer initialiser for development mode.

As models get reloaded on every request in development mode, these
callbacks were running unpredictably, depending on how many requests had
been made.
