Sha256: 630f30193d940b6555288f4429642ac941c27886bdde404527f54b9d1abd762a
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
# A single word in the search index. class PoseWord < ActiveRecord::Base has_many :pose_assignments attr_accessible :text def self.remove_unused_words progress_bar = nil if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) # Will generate something like: # # DELETE FROM "pose_words" WHERE "pose_words"."id" IN # (SELECT "pose_words"."id" FROM "pose_words" INNER JOIN "pose_assignments" ON "pose_assignments"."pose_word_id" = "pose_words"."id" # HAVING.... GROUP BY "pose_words"."id") PoseWord.delete_all(id: PoseWord.select("pose_words.id"). joins("LEFT OUTER JOIN pose_assignments ON pose_assignments.pose_word_id = pose_words.id"). group("pose_words.id"). having("COUNT(pose_assignments.id) = 0")) else # NOTE (SZ): do not use find_each uses batch_size == 100. # Use find_in_batches instead. # PoseWord.select(:id).find_in_batches.each(include: [:pose_assignments], batch_size: 5000) do |pose_word| pose_word.delete if pose_word.pose_assignments.size == 0 progress_bar.inc if progress_bar end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
pose-1.3.3 | lib/pose/models/pose_word.rb |
pose-1.3.2 | lib/pose/models/pose_word.rb |
pose-1.3.1 | lib/pose/models/pose_word.rb |
pose-1.3 | lib/pose/models/pose_word.rb |