<commit_before>require 'sweeper_helper'
class PlaylistItemSweeper < ActionController::Caching::Sweeper
  include SweeperHelper
  observe PlaylistItem

  def actual_object_clear(actual_object)
    begin
      if actual_object.present?
        Rails.cache.delete("#{actual_object.class.to_s.downcase}-barcode-#{actual_object.id}")
        Rails.cache.delete("views/#{actual_object.class.to_s.downcase}-barcode-html-#{actual_object.id}")
        if [Playlist, Collage, Case].include?(actual_object.class)
          ActionController::Base.expire_page "/#{actual_object.class.to_s.tableize}/#{actual_object.id}.html"
          ActionController::Base.expire_page "/#{actual_object.class.to_s.tableize}/#{actual_object.id}/export.html"
        end
      end
    rescue Exception => e
      Rails.logger.warn "Playlist item sweeper error: #{e.inspect}"
    end
  end

  def after_create(record)
    clear_playlists([record])
    actual_object_clear(record.actual_object)
  end

  def after_update(record)
    clear_playlists([record])
  end

  def before_destroy(record)
    actual_object_clear(record.actual_object)
  end
end<commit_msg>Fixed caching issue on playlist item delete.<commit_after>require 'sweeper_helper'
class PlaylistItemSweeper < ActionController::Caching::Sweeper
  include SweeperHelper
  observe PlaylistItem

  def actual_object_clear(actual_object)
    begin
      if actual_object.present?
        Rails.cache.delete("#{actual_object.class.to_s.downcase}-barcode-#{actual_object.id}")
        Rails.cache.delete("views/#{actual_object.class.to_s.downcase}-barcode-html-#{actual_object.id}")
        if [Playlist, Collage, Case].include?(actual_object.class)
          ActionController::Base.expire_page "/#{actual_object.class.to_s.tableize}/#{actual_object.id}.html"
          ActionController::Base.expire_page "/#{actual_object.class.to_s.tableize}/#{actual_object.id}/export.html"
        end
      end
    rescue Exception => e
      Rails.logger.warn "Playlist item sweeper error: #{e.inspect}"
    end
  end

  def after_create(record)
    clear_playlists([record])
    actual_object_clear(record.actual_object)
  end

  def after_update(record)
    clear_playlists([record])
  end

  def before_destroy(record)
    clear_playlists([record])
    actual_object_clear(record.actual_object)
  end
end
{'fraction_non_alphanumeric': 0.11331322705730289, 'fraction_numerical': 0.0, 'mean_word_length': 4.194630872483222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1196734', 'n_tokens_mistral': 742, 'n_tokens_neox': 750, 'n_words': 108}