Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'bulk_insert'
- old_logger = ActiveRecord::Base.logger
- ActiveRecord::Base.logger = nil
- model = WhateverModel.find_by(whatever: 'something')
- tag_names = ('a'..'i').to_a.permutation.to_a.shuffle.map(&:join)
- tag_names_count = tag_names.count
- max_id = ActsAsTaggableOn::Tag.maximum(:id)
- puts "Inserting tags..."
- tags = tag_names.map.with_index do |tag_name, i|
- { name: tag_name }
- end
- ActsAsTaggableOn::Tag.bulk_insert(
- set_size: 10_000, values: tags
- )
- tag_ids = ActsAsTaggableOn::Tag.where("id > ?", max_id).select(:id).pluck(:id)
- puts "Inserting taggings..."
- taggings = tag_ids.map do |tag_id|
- { taggable_id: model.id, tag_id: tag_id, context: 'tags', taggable_type: 'WhateverModel' }
- end
- ActsAsTaggableOn::Tagging.bulk_insert(
- set_size: 10_000, values: taggings
- )
- ActiveRecord::Base.logger = old_logger
Add Comment
Please, Sign In to add comment