
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
active-record-transactioner
Advanced tools
Queue saving and destroying of many models into transactions through multiple threads for optimal database-performance in ActiveRecord.
Add to your Gemfile and bundle:
gem 'active-record-transactioner'
save!
.ActiveRecordTransactioner.new do |trans|
models.each do |model|
model.some_attribute = "some_value"
trans.save!(model)
end
end
You can also do it a bit more complicated with some custom options.
ActiveRecordTransactioner.new(
transaction_method: :transaction,
transaction_size: 1000,
threadded: false
) do |trans|
models.each do |model|
model.some_attribute = "some_value"
trans.save!(model)
end
end
ActiveRecordTransactioner.new do |trans|
models.each do |model|
trans.update_columns(model, some_column: "new_value")
end
end
ActiveRecordTransactioner.new do |trans|
1000.times do |count|
trans.bulk_create!(User.new(email: "test#{count}@example.com"))
end
end
ActiveRecordTransactioner.new do |trans|
models.each do |model|
trans.destroy!(model)
end
end
The "threadded" and "max_running_threads" options will start new threads to do the saving of the models, while continuing to queue up new models in the primary thread. This way the database can utilize multiple cores, and if you use a threadded VM like JRuby or Rubinius, you will utilize even more.
This can help greatly speed up the processing of records.
Be aware that the saving of only one type of model, will be limited to only one thread, so it will make sense to try and queue up as many type of models as possible. Like users, orders and so on.
ActiveRecordTransactioner.new(
threadded: true,
max_running_threads: 3
) do |trans|
models.each do |model|
model.some_attribute = "some_value"
trans.save!(model)
end
end
Copyright (c) 2013 Kasper Johansen. See LICENSE.txt for further details.
FAQs
Unknown package
We found that active-record-transactioner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.