有近100万条用户记录,因此我们删除非活动用户以保持表一致性。我们正在使用Sinatra框架。
在我们的模型中:
class UserInfo < ActiveRecord::Base
def delete_expired_users
begin
@expired_users = UserInfo.where("status != ? and UEndDate < ?", "active", 3.months.ago )
@expired_users.find_each do |user| # as we have 500k records to delete, used "find_each" IS THIS ASYNCHRONOUS WAY TO DELETE?
user.destroy
# I NEED TO STORE THIS DESTROYED USER IN A CSV FILE.
end
rescue
raise
end
end
end