Sha256: 72d1edf5ed2edc446ebe2c7795e9c8c6a4d80e4399ef78423cd168b8a20d8a7c
Contents?: true
Size: 1.15 KB
Versions: 3
Compression:
Stored size: 1.15 KB
Contents
# Assigns searchable objects to words in the search index. module Pose class Assignment < ActiveRecord::Base attr_accessible :word, :posable belongs_to :word, class_name: 'Pose::Word' belongs_to :posable, polymorphic: true # Removes all Assignments for the given class. def self.delete_class_index clazz Assignment.delete_all(posable_type: clazz.name) end # Removes all Assignments that aren't used anymore. def self.cleanup_orphaned_pose_assignments progress_bar = nil Assignment.find_each(include: [:posable, :word], batch_size: 5000) do |assignment| progress_bar.increment 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 Pose::Word for it no longer exists. if assignment.word.nil? puts "deleting assignment '#{assignment.id}' because its word no longer exists." assignment.delete end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pose-2.1.0 | app/models/pose/assignment.rb |
pose-2.0.1 | app/models/pose/assignment.rb |
pose-2.0.0 | app/models/pose/assignment.rb |