<commit_before># frozen_string_literal: true

# == Schema Information
#
# Table name: classroom_units
#
#  id                   :integer          not null, primary key
#  assign_on_join       :boolean          default(FALSE)
#  assigned_student_ids :integer          default([]), is an Array
#  visible              :boolean          default(TRUE)
#  created_at           :datetime
#  updated_at           :datetime
#  classroom_id         :integer          not null
#  unit_id              :integer          not null
#
# Indexes
#
#  index_classroom_units_on_classroom_id              (classroom_id)
#  index_classroom_units_on_unit_id                   (unit_id)
#  index_classroom_units_on_unit_id_and_classroom_id  (unit_id,classroom_id) UNIQUE
#
# Foreign Keys
#
#  fk_rails_...  (classroom_id => classrooms.id)
#  fk_rails_...  (unit_id => units.id)
#
class ClassroomUnit < ApplicationRecord
  include ::NewRelic::Agent
  include AtomicArrays

  belongs_to :unit # Note, there is a touch in the unit -> classroom_unit direction, so don't add one here.
  belongs_to :classroom, touch: true
  has_many :activity_sessions
  has_many :unit_activities, through: :unit
  has_many :completed_activity_sessions, -> {completed}, class_name: 'ActivitySession'
  has_many :classroom_unit_activity_states

  validates :unit, uniqueness: { scope: :classroom }
  before_save :check_for_assign_on_join_and_update_students_array_if_true<commit_msg>Remove touch causing deadlock for now.<commit_after># frozen_string_literal: true

# == Schema Information
#
# Table name: classroom_units
#
#  id                   :integer          not null, primary key
#  assign_on_join       :boolean          default(FALSE)
#  assigned_student_ids :integer          default([]), is an Array
#  visible              :boolean          default(TRUE)
#  created_at           :datetime
#  updated_at           :datetime
#  classroom_id         :integer          not null
#  unit_id              :integer          not null
#
# Indexes
#
#  index_classroom_units_on_classroom_id              (classroom_id)
#  index_classroom_units_on_unit_id                   (unit_id)
#  index_classroom_units_on_unit_id_and_classroom_id  (unit_id,classroom_id) UNIQUE
#
# Foreign Keys
#
#  fk_rails_...  (classroom_id => classrooms.id)
#  fk_rails_...  (unit_id => units.id)
#
class ClassroomUnit < ApplicationRecord
  include ::NewRelic::Agent
  include AtomicArrays

  belongs_to :unit # Note, there is a touch in the unit -> classroom_unit direction, so don't add one here.
  # TODO: put this touch back in for caching
  belongs_to :classroom #, touch: true
  has_many :activity_sessions
  has_many :unit_activities, through: :unit
  has_many :completed_activity_sessions, -> {completed}, class_name: 'ActivitySession'
  has_many :classroom_unit_activity_states

  validates :unit, uniqueness: { scope: :classroom }
  before_save :check_for_assign_on_join_and_update_students_array_if_true
{'fraction_non_alphanumeric': 0.0780189959294437, 'fraction_numerical': 0.0, 'mean_word_length': 3.1360448807854135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7312304', 'n_tokens_mistral': 933, 'n_tokens_neox': 915, 'n_words': 216}