<commit_before>require 'i18n/backend/base'

module I18n
  module Backend
    class Releaf
      autoload :Translation,      'i18n/backend/releaf/translation'
      autoload :TranslationData,  'i18n/backend/releaf/translation_data'
      autoload :TranslationGroup, 'i18n/backend/releaf/translation_group'


      module Implementation
        include Base, Flatten
        DEFAULT_SCOPE = ['global']

        def available_locales
          TranslationData.select(:lang).group(:lang).pluck(:lang)
        rescue ::ActiveRecord::StatementInvalid
          []
        end

        def store_translations(locale, data, options = {})
        end

        def reload_cache
          I18N_CACHE.clear
          Translation.get_translated.find_each do |translation|
            I18N_CACHE.write [translation.lang, translation.key], translation.localization
          end
          I18N_CACHE.write('UPDATED_AT', Settings.i18n_updated_at)
        end

        protected



        def check_cache
          return if I18N_CACHE.read('UPDATED_AT') == Settings.i18n_updated_at
          reload_cache
        end

        # Lookup translation from database
        def lookup(locale, key, scope = [], options = {})<commit_msg>Mass loading to cache optimized<commit_after>require 'i18n/backend/base'

module I18n
  module Backend
    class Releaf
      autoload :Translation,      'i18n/backend/releaf/translation'
      autoload :TranslationData,  'i18n/backend/releaf/translation_data'
      autoload :TranslationGroup, 'i18n/backend/releaf/translation_group'


      module Implementation
        include Base, Flatten
        DEFAULT_SCOPE = ['global']

        def available_locales
          TranslationData.select(:lang).group(:lang).pluck(:lang)
        rescue ::ActiveRecord::StatementInvalid
          []
        end

        def store_translations(locale, data, options = {})
        end

        def reload_cache
          I18N_CACHE.clear

          query = Translation.joins(:translation_data)
          query = query.select(["releaf_translations.key", "releaf_translation_data.lang", "releaf_translation_data.localization"])

          query.each do |translation|
            I18N_CACHE.write [translation.lang, translation.key], translation.localization
          end
          I18N_CACHE.write('UPDATED_AT', Settings.i18n_updated_at)
        end

        protected



        def check_cache
          return if I18N_CACHE.read('UPDATED_AT') == Settings.i18n_updated_at
          reload_cache
        end

        # Lookup translation from database
        def lookup(locale, key, scope = [], options = {})
{'fraction_non_alphanumeric': 0.08387590961317502, 'fraction_numerical': 0.01685178092684795, 'mean_word_length': 2.5154777927321668, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2981409', 'n_tokens_mistral': 774, 'n_tokens_neox': 721, 'n_words': 144}