Sha256: 95b4cab34164d057f466587d221c9bfad1f5b91a63a207186682df2a6369d09c

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 KB

Contents

# Assigns searchable objects to words in the search index.
class PoseAssignment < ActiveRecord::Base
  belongs_to :pose_word
  belongs_to :posable, :polymorphic => true

  # Removes all PoseAssignments for the given class.
  def self.delete_class_index clazz
    PoseAssignment.delete_all(['posable_type=?', clazz.name])
  end

  # Removes all PoseAssignments that aren't used anymore.
  def self.cleanup_orphaned_pose_assignments progress_bar = nil
    PoseAssignment.find_each(:include => [:posable, :pose_word], :batch_size => 5000) do |assignment|
      progress_bar.inc if progress_bar

      # Delete the assignment if the posable object no longer exists.
      if assignment.posable.nil?
        puts "deleting assignment '#{assignment.id}' because the posable object no longer exists."
        assignment.delete
        next
      end

      # Delete the assignment if the PoseWord for it no longer exists.
      if assignment.pose_word.nil?
        puts "deleting assignment '#{assignment.id}' because its word no longer exists."
        assignment.delete
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pose-1.1.0 lib/pose/models/pose_assignment.rb
pose-1.0.0 lib/pose_assignment.rb
pose-0.3 lib/pose_assignment.rb
pose-0.2.6 lib/pose_assignment.rb
pose-0.2.5 lib/pose_assignment.rb
pose-0.2.4 lib/pose_assignment.rb
pose-0.2.3 lib/pose_assignment.rb
pose-0.2.2 lib/pose_assignment.rb
pose-0.2.1 lib/pose_assignment.rb