<commit_before># frozen_string_literal: true

#
# == OptionalModules namespace
#
module OptionalModules
  #
  # == BloggableConcern
  #
  module Bloggable
    extend ActiveSupport::Concern

    included do
      before_action :blog_module_enabled?
      before_action :set_blog_settings, only: [:index, :show]
      before_action :set_blog_categories, only: [:index, :show]
      before_action :set_last_blogs, only: [:index, :show]
      before_action :set_last_comments, only: [:index, :show], if: proc { @comment_module.enabled? }

      LAST_COMMENTS_COUNT = 5

      def blog_module_enabled?
        not_found unless @blog_module.enabled?
      end

      def set_blog_settings
        @blog_settings = BlogSetting.first
      end

      def set_blog_categories
        @blog_categories = BlogCategory.includes(:translations).all
      end

      def set_last_blogs
        @last_blogs = Blog.select(:id, :title, :blog_category_id, :updated_at).includes(:comments, :translations, blog_category: [:translations]).online.order('created_at DESC').first(5)
      end

      def set_last_comments
        last_comments = Comment.includes(:user, :commentable).only_blogs.by_locale(@language).validated.first(LAST_COMMENTS_COUNT).reject { |r| !r.commentable.online? }
        @last_comments = CommentDecorator.decorate_collection(last_comments)
        gon.push(last_comments_count: LAST_COMMENTS_COUNT)
      end
    end
  end
end<commit_msg>Blog/sidebar :: Setup constante to define last blogs count to display in sidebar<commit_after># frozen_string_literal: true

#
# == OptionalModules namespace
#
module OptionalModules
  #
  # == BloggableConcern
  #
  module Bloggable
    extend ActiveSupport::Concern

    included do
      before_action :blog_module_enabled?
      before_action :set_blog_settings, only: [:index, :show]
      before_action :set_blog_categories, only: [:index, :show]
      before_action :set_last_blogs, only: [:index, :show]
      before_action :set_last_comments, only: [:index, :show], if: proc { @comment_module.enabled? }

      LAST_COMMENTS_COUNT = 5
      LAST_BLOGS_COUNT = 5

      def blog_module_enabled?
        not_found unless @blog_module.enabled?
      end

      def set_blog_settings
        @blog_settings = BlogSetting.first
      end

      def set_blog_categories
        @blog_categories = BlogCategory.includes(:translations).all
      end

      def set_last_blogs
        @last_blogs = Blog.select(:id, :title, :blog_category_id, :updated_at).includes(:comments, :translations, blog_category: [:translations]).online.order('created_at DESC').first(LAST_BLOGS_COUNT)
      end

      def set_last_comments
        last_comments = Comment.includes(:user, :commentable).only_blogs.by_locale(@language).validated.first(LAST_COMMENTS_COUNT).reject { |r| !r.commentable.online? }
        @last_comments = CommentDecorator.decorate_collection(last_comments)
        gon.push(last_comments_count: LAST_COMMENTS_COUNT)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09428284854563691, 'fraction_numerical': 0.0013373453694416582, 'mean_word_length': 3.7567567567567566, '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': '1457616', 'n_tokens_mistral': 951, 'n_tokens_neox': 912, 'n_words': 180}