Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kml/79bd8cedf64caadd18ca to your computer and use it in GitHub Desktop.

Select an option

Save kml/79bd8cedf64caadd18ca to your computer and use it in GitHub Desktop.
Eager load data before first request
# encoding: utf-8
# Source: https://gist.github.com/kml/79bd8cedf64caadd18ca
require "active_support/i18n_railtie"
# Eager load translations.
# https://github.com/svenfuchs/i18n/blob/master/lib/i18n/backend/simple.rb
# rails c
# I18n.backend.initialized?
module I18n
class Railtie
protected
class << self
alias original_initialize_i18n initialize_i18n
def initialize_i18n(app)
original_initialize_i18n(app).tap do
unless I18n.backend.initialized?
I18n.backend.send(:init_translations)
end
end
end
end
end
end
require "active_support/multibyte/unicode"
# Eager load the Unicode database
# - opposite to default "Lazy load" strategy
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/multibyte/unicode.rb#L320
ActiveSupport::Multibyte::Unicode.send(:database).load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment