<commit_before>require_dependency 'global_registry_methods'

class TeamMember < ActiveRecord::Base
  include Sidekiq::Worker
  include GlobalRegistryMethods

  self.table_name	= "ministry_missional_team_member"
  self.primary_key = "id"
  belongs_to :team, :foreign_key => "teamID"
  belongs_to :person, :foreign_key => "personID"

  delegate :global_registry_id, to: :person

  def async_push_to_global_registry
    self.class.push_structure_to_global_registry

    if team && person
      team.async_push_to_global_registry unless team.global_registry_id.present?
      person.async_push_to_global_registry unless person.global_registry_id.present?
      team_relationships = []
      person.teams.each do |team|
        team_relationships << {
            ministry: team.global_registry_id,
            role: is_leader? ? 'Leader' : 'Member'
        }
      end
      @attributes_to_push = {
        'ministry:relationship' => team_relationships,
      }

      update_in_global_registry
    end
  end

  def self.push_structure_to_global_registry
    Team.push_structure_to_global_registry
    Person.push_structure_to_global_registry

    # Make sure relationships are defined
    team_entity_type = Rails.cache.fetch(:team_entity_type, expires_in: 1.hour) do
      GlobalRegistry::EntityType.get({'filters[name]' => 'ministry'})['entity_types'].first
    end
    person_entity_type = Rails.cache.fetch(:activity_entity_type, expires_in: 1.hour) do
      GlobalRegistry::EntityType.get({'filters[name]' => 'person'})['entity_types'].first
    end
    role_enum_entity_type = Rails.cache.fetch(:role_enum_entity_type, expires_in: 1.hour) do
      GlobalRegistry::EntityType.get({'filters[name]' => 'role'})['entity_types'].first
    end

    person_team_relationship_type = Rails.cache.fetch(:person_team_relationship_type, expires_in: 1.hour) do
      GlobalRegistry::RelationshipType.get({'filters[between]' => "#{team_entity_type['id']},#{person_entity_type['id']}"})['relationship_types'].first
    end<commit_msg>Fix cache key for person_entity_type<commit_after>require_dependency 'global_registry_methods'

class TeamMember < ActiveRecord::Base
  include Sidekiq::Worker
  include GlobalRegistryMethods

  self.table_name	= "ministry_missional_team_member"
  self.primary_key = "id"
  belongs_to :team, :foreign_key => "teamID"
  belongs_to :person, :foreign_key => "personID"

  delegate :global_registry_id, to: :person

  def async_push_to_global_registry
    self.class.push_structure_to_global_registry

    if team && person
      team.async_push_to_global_registry unless team.global_registry_id.present?
      person.async_push_to_global_registry unless person.global_registry_id.present?
      team_relationships = []
      person.teams.each do |team|
        team_relationships << {
            ministry: team.global_registry_id,
            role: is_leader? ? 'Leader' : 'Member'
        }
      end
      @attributes_to_push = {
        'ministry:relationship' => team_relationships,
      }

      update_in_global_registry
    end
  end

  def self.push_structure_to_global_registry
    Team.push_structure_to_global_registry
    Person.push_structure_to_global_registry

    # Make sure relationships are defined
    team_entity_type = Rails.cache.fetch(:team_entity_type, expires_in: 1.hour) do
      GlobalRegistry::EntityType.get({'filters[name]' => 'ministry'})['entity_types'].first
    end
    person_entity_type = Rails.cache.fetch(:person_entity_type, expires_in: 1.hour) do
      GlobalRegistry::EntityType.get({'filters[name]' => 'person'})['entity_types'].first
    end
    role_enum_entity_type = Rails.cache.fetch(:role_enum_entity_type, expires_in: 1.hour) do
      GlobalRegistry::EntityType.get({'filters[name]' => 'role'})['entity_types'].first
    end

    person_team_relationship_type = Rails.cache.fetch(:person_team_relationship_type, expires_in: 1.hour) do
      GlobalRegistry::RelationshipType.get({'filters[between]' => "#{team_entity_type['id']},#{person_entity_type['id']}"})['relationship_types'].first
    end
{'fraction_non_alphanumeric': 0.1057810578105781, 'fraction_numerical': 0.0019680196801968018, 'mean_word_length': 4.577503429355281, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '7626651', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1246, 'n_words': 195}