<commit_before>class CommunityTrackPlugin::TrackListBlock < Block

  include CommunityTrackPlugin::StepHelper

  settings_items :limit, :type => :integer, :default => 3
  settings_items :more_another_page, :type => :boolean, :default => false
  settings_items :category_ids, :type => Array, :default => []

  def self.description
    _('Track List')
  end

  def help
    _('This block displays a list of most relevant tracks.')
  end

  def track_partial
    'track'
  end

  def tracks(page=1, per_page=limit)
    all_tracks.order('hits DESC').paginate(:per_page => per_page, :page => page)
  end

  def count_tracks
    all_tracks.count
  end

  def accept_category?(cat)
    true #accept all?
  end

  def category_ids=(ids)
    settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact
  end

  def all_tracks
    tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track')
    if !category_ids.empty?
      tracks = tracks.joins(:article_categorizations).where(:articles_categories => {:category_id => category_ids})
    end
    tracks
  end

  def content(args={})
    block = self
    lambda do
      render :file => 'blocks/track_list.rhtml', :locals => {:block => block}
    end
  end

  def has_page?(page, per_page=limit)
    return (page-1) * per_page < count_tracks
  end

  def footer
    block = self
    return nil if !has_page?(2)
    lambda do
      render :partial => 'blocks/track_list_more', :locals => {:block => block, :page => 2, :per_page => block.limit}
    end
  end

  def self.expire_on
    { :profile => [:article], :environment => [:article] }
  end

end<commit_msg>Expire cache of track block when change a category<commit_after>class CommunityTrackPlugin::TrackListBlock < Block

  include CommunityTrackPlugin::StepHelper

  settings_items :limit, :type => :integer, :default => 3
  settings_items :more_another_page, :type => :boolean, :default => false
  settings_items :category_ids, :type => Array, :default => []

  def self.description
    _('Track List')
  end

  def help
    _('This block displays a list of most relevant tracks.')
  end

  def track_partial
    'track'
  end

  def tracks(page=1, per_page=limit)
    all_tracks.order('hits DESC').paginate(:per_page => per_page, :page => page)
  end

  def count_tracks
    all_tracks.count
  end

  def accept_category?(cat)
    true #accept all?
  end

  def category_ids=(ids)
    settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact
  end

  def all_tracks
    tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track')
    if !category_ids.empty?
      tracks = tracks.joins(:article_categorizations).where(:articles_categories => {:category_id => category_ids})
    end
    tracks
  end

  def content(args={})
    block = self
    lambda do
      render :file => 'blocks/track_list.rhtml', :locals => {:block => block}
    end
  end

  def has_page?(page, per_page=limit)
    return (page-1) * per_page < count_tracks
  end

  def footer
    block = self
    return nil if !has_page?(2)
    lambda do
      render :partial => 'blocks/track_list_more', :locals => {:block => block, :page => 2, :per_page => block.limit}
    end
  end

  def self.expire_on
    { :profile => [:article, :category], :environment => [:article, :category] }
  end

end
{'fraction_non_alphanumeric': 0.12293853073463268, 'fraction_numerical': 0.0029985007496251873, 'mean_word_length': 3.5887207702888584, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7392988', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1071, 'n_words': 281}