百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

delete_in_batches

> 编程语言
开源

快速批次删除活动记录和邮件

199 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

快速批次删除活动记录和邮件

delete_in_batches

:fire: Fast batch deletes for Active Record and Postgres

Installation

Add this line to your application’s Gemfile:

ruby
gem 'delete_in_batches'

How to Use

Delete rows in batches

ruby
Tweet.where(user_id: 1).delete_in_batches

Important: Be sure to test your query before running it in production

Change the batch size

ruby
Tweet.where(user_id: 1).delete_in_batches(batch_size: 50000) # defaults to 10000

Sleep between batches

ruby
Tweet.where(user_id: 1).delete_in_batches(sleep: 0.01)

Show progress

ruby
Tweet.where(user_id: 1).delete_in_batches do
  puts "Another batch deleted"
end

Works with associations

ruby
user.tweets.delete_in_batches

To delete all rows in a table, TRUNCATE is fastest.

ruby
ActiveRecord::Base.connection.execute("TRUNCATE tweets")

History

View the changelog

Note: This project originally had the description “the fastest way to delete 100k+ rows with ActiveRecord” but a single DELETE statement will likely be faster. See this discussion for more details.

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development:

bash
git clone https://github.com/ankane/delete_in_batches.git
cd delete_in_batches
bundle install
bundle exec rake test

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言