<commit_before>namespace :check do
  namespace :migrate do
    task update_cached_fields: :environment do
      started = Time.now.to_i
      interval = CheckConfig.get('cache_interval', 30).to_i
      cache_date = Time.now - interval.days
      team_count = Team.count
      team_counter = 0
      Team.find_each do |team|
        team_counter += 1
        puts "[#{Time.now}] Processing team #{team_counter}/#{team_count}: #{team.slug}"
        query = team.project_medias.where('updated_at > ?', cache_date)
        pm_count = query.count
        pm_counter = 0
        query.find_each do |pm|
          pm_counter += 1
          puts "[#{Time.now}] Processing item #{pm_counter}/#{pm_count} from team #{team_counter}/#{team_count}: ##{pm.id}"
          pm.list_columns_values
        end
      end
      minutes = ((Time.now.to_i - started) / 60).to_i
      puts "[#{Time.now}] Done in #{minutes} minutes."
    end
  end
end<commit_msg>Fixing rake task to update cache for items after the "cache_interval" configuration key is updated (CHECK-2129)<commit_after>namespace :check do
  namespace :migrate do
    task update_cached_fields: :environment do
      CACHED_FIELDS = [
        'linked_items_count', 'suggestions_count', 'is_suggested', 'is_confirmed', 'related_count',
        'requests_count', 'demand', 'last_seen', 'description', 'title', 'status', 'share_count',
        'reaction_count', 'comment_count', 'report_status', 'tags_as_sentence', 'sources_as_sentence',
        'media_published_at', 'published_by', 'type_of_media', 'added_as_similar_by_name',
        'confirmed_as_similar_by_name', 'folder', 'show_warning_cover', 'picture',
        'team_name', 'creator_name'
      ]

      started = Time.now.to_i
      interval = CheckConfig.get('cache_interval', 30).to_i
      cache_date = Time.now - interval.days
      team_count = Team.count
      team_counter = 0
      Team.find_each do |team|
        team_counter += 1
        puts "[#{Time.now}] Processing team #{team_counter}/#{team_count}: #{team.slug}"
        query = team.project_medias.where('updated_at > ?', cache_date)
        pm_count = query.count
        pm_counter = 0
        query.find_each do |pm|
          pm_counter += 1
          failed = false
          begin
            pm.list_columns_values
            CACHED_FIELDS.each { |field| pm.send(field) } # Just cache if it's not cached yet
          rescue Exception => e
            failed = e.message
          end
          puts "[#{Time.now}] Processed item #{pm_counter}/#{pm_count} from team #{team_counter}/#{team_count}: ##{pm.id} (#{failed ? 'failed with ' + e.message : 'success'})"
        end
      end
      minutes = ((Time.now.to_i - started) / 60).to_i
      puts "[#{Time.now}] Done in #{minutes} minutes."
    end
  end
end
{'fraction_non_alphanumeric': 0.12697274031563846, 'fraction_numerical': 0.007173601147776184, 'mean_word_length': 2.7537012113055184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2366791', 'n_tokens_mistral': 892, 'n_tokens_neox': 878, 'n_words': 206}