<commit_before># frozen_string_literal: true

require_dependency "gobierto_plans"

module GobiertoPlans
  class Plan < ApplicationRecord
    acts_as_paranoid column: :archived_at

    include ActsAsParanoidAliases
    include GobiertoCommon::Sluggable

    belongs_to :site
    belongs_to :plan_type
    belongs_to :categories_vocabulary, class_name: "GobiertoCommon::Vocabulary", foreign_key: :vocabulary_id
    belongs_to :statuses_vocabulary, class_name: "GobiertoCommon::Vocabulary", foreign_key: :statuses_vocabulary_id
    has_many :categories, through: :categories_vocabulary, source: :terms, class_name: "GobiertoCommon::Term"

    translates :title, :introduction, :footer

    enum visibility_level: { draft: 0, published: 1 }

    after_restore :set_slug

    validates :site, :title, :introduction, :plan_type_id, :year, presence: true
    validates :year, uniqueness: { scope: :plan_type }
    validates :slug, uniqueness: { scope: :site_id }

    scope :sort_by_updated_at, -> { order(updated_at: :desc) }
    scope :sort_by_year, -> { order(year: :desc) }

    def configuration_data
      data = read_attribute(:configuration_data)
      JSON.parse(data) unless data.blank?
    end

    def nodes
      Node.joins(categories: [:vocabulary]).where(terms: { vocabulary_id: categories_vocabulary&.id })
    end
<commit_msg>Memoize nodes<commit_after># frozen_string_literal: true

require_dependency "gobierto_plans"

module GobiertoPlans
  class Plan < ApplicationRecord
    acts_as_paranoid column: :archived_at

    include ActsAsParanoidAliases
    include GobiertoCommon::Sluggable

    belongs_to :site
    belongs_to :plan_type
    belongs_to :categories_vocabulary, class_name: "GobiertoCommon::Vocabulary", foreign_key: :vocabulary_id
    belongs_to :statuses_vocabulary, class_name: "GobiertoCommon::Vocabulary", foreign_key: :statuses_vocabulary_id
    has_many :categories, through: :categories_vocabulary, source: :terms, class_name: "GobiertoCommon::Term"

    translates :title, :introduction, :footer

    enum visibility_level: { draft: 0, published: 1 }

    after_restore :set_slug

    validates :site, :title, :introduction, :plan_type_id, :year, presence: true
    validates :year, uniqueness: { scope: :plan_type }
    validates :slug, uniqueness: { scope: :site_id }

    scope :sort_by_updated_at, -> { order(updated_at: :desc) }
    scope :sort_by_year, -> { order(year: :desc) }

    def configuration_data
      data = read_attribute(:configuration_data)
      JSON.parse(data) unless data.blank?
    end

    def nodes
      @nodes ||= Node.joins(categories: [:vocabulary]).where(terms: { vocabulary_id: categories_vocabulary&.id })
    end

{'fraction_non_alphanumeric': 0.09765188222139397, 'fraction_numerical': 0.0014908684308609765, 'mean_word_length': 4.834782608695652, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4870966', 'n_tokens_mistral': 894, 'n_tokens_neox': 865, 'n_words': 190}