<commit_before># == Schema Information
# Schema version: 20090216032013
#
# Table name: topics
#
#  id                :integer(4)      not null, primary key
#  forum_id          :integer(4)      
#  person_id         :integer(4)      
#  name              :string(255)     
#  forum_posts_count :integer(4)      default(0), not null
#  created_at        :datetime        
#  updated_at        :datetime        
#

class Topic < ActiveRecord::Base
  include ActivityLogger
  
  MAX_NAME = 100
  NUM_RECENT = 6
  DEFAULT_REFRESH_SECONDS = 30
  
  attr_accessible :name
  
  belongs_to :forum, :counter_cache => true
  belongs_to :person
  has_many :posts, :order => 'created_at DESC', :dependent => :destroy,
                   :class_name => "ForumPost"
  has_many :viewers, :dependent => :destroy
  has_many :activities, :foreign_key => "item_id", :conditions => "item_type = 'Topic'", :dependent => :destroy
  validates_presence_of :name, :forum, :person
  validates_length_of :name, :maximum => MAX_NAME
  
  after_create :log_activity
  
  def self.find_recent
    find(:all, :order => "created_at DESC", :limit => NUM_RECENT)
  end

  def self.find_recently_active(forum, page = 1)
    topics = forum.topics.paginate(:page => page)
  end

  def update_viewer(person)
    current_viewer = self.viewers.find_or_create_by_person_id(person.id)
    current_viewer.touch
  end

  def current_viewers(seconds_ago)
    self.viewers.all(:conditions => ['updated_at > ?', Time.now.ago(seconds_ago).utc])
  end

  def posts_since_last_refresh(last_refresh_time, person_id)
    self.posts.all(:conditions => ['created_at > ? and person_id != ?', Time.at(last_refresh_time + 1).utc, person_id], 
                   :order => 'created_at DESC')
  end

  private
  
    def log_activity
      add_activities(:item => self, :person => person, :group => self.forum.group)
    end<commit_msg>groupy branch: eager load topic ajax queries<commit_after># == Schema Information
# Schema version: 20090216032013
#
# Table name: topics
#
#  id                :integer(4)      not null, primary key
#  forum_id          :integer(4)      
#  person_id         :integer(4)      
#  name              :string(255)     
#  forum_posts_count :integer(4)      default(0), not null
#  created_at        :datetime        
#  updated_at        :datetime        
#

class Topic < ActiveRecord::Base
  include ActivityLogger
  
  MAX_NAME = 100
  NUM_RECENT = 6
  DEFAULT_REFRESH_SECONDS = 30
  
  attr_accessible :name
  
  belongs_to :forum, :counter_cache => true
  belongs_to :person
  has_many :posts, :order => 'created_at DESC', :dependent => :destroy,
                   :class_name => "ForumPost"
  has_many :viewers, :dependent => :destroy
  has_many :activities, :foreign_key => "item_id", :conditions => "item_type = 'Topic'", :dependent => :destroy
  validates_presence_of :name, :forum, :person
  validates_length_of :name, :maximum => MAX_NAME
  
  after_create :log_activity
  
  def self.find_recent
    find(:all, :order => "created_at DESC", :limit => NUM_RECENT)
  end

  def self.find_recently_active(forum, page = 1)
    topics = forum.topics.paginate(:page => page)
  end

  def update_viewer(person)
    current_viewer = self.viewers.find_or_create_by_person_id(person.id)
    current_viewer.touch
  end

  def current_viewers(seconds_ago)
    self.viewers.all(:conditions => ['updated_at > ?', Time.now.ago(seconds_ago).utc], :include => :person)
  end

  def posts_since_last_refresh(last_refresh_time, person_id)
    self.posts.all(:conditions => ['created_at > ? and person_id != ?', Time.at(last_refresh_time + 1).utc, person_id], 
                   :include => :person, :order => 'created_at DESC')
  end

  private
  
    def log_activity
      add_activities(:item => self, :person => person, :group => self.forum.group)
    end
{'fraction_non_alphanumeric': 0.11465134499869417, 'fraction_numerical': 0.015669887699138157, 'mean_word_length': 3.1405405405405404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '4249265', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1268, 'n_words': 277}