Sha256: 06955b563de4ca888d7a6f002f1f52201fd7b4784b3105458f3e425c4779e630

Contents?: true

Size: 908 Bytes

Versions: 1

Compression:

Stored size: 908 Bytes

Contents

# A single word in the search index.
module Pose
  class Word < ActiveRecord::Base
    has_many :assignments, class_name: 'Pose::Assignment', dependent: :destroy

    def self.remove_unused_words progress_bar = nil
      if Helpers.is_sql_database?
        # SQL database --> use an optimized query.
        Word.delete_all(id: Word.select("pose_words.id").
                                 joins("LEFT OUTER JOIN pose_assignments ON pose_assignments.word_id = pose_words.id").
                                 group("pose_words.id").
                                 having("COUNT(pose_assignments.id) = 0"))
      else
        # Unknown database --> use the standard Rails API.
        Word.select(:id).find_each(include: [:assignments], batch_size: 100) do |word|
          word.delete if word.assignments.size == 0
          progress_bar.increment if progress_bar
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pose-3.0.0 app/models/pose/word.rb