
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.
create_update_destroy_async
Advanced tools
A simple benchmark to grab your attention. Performance difference is noticeable.
A very simple solution for a very simple but annoying problem. An example of problem that this gem solves.
#
# code that can be improved
#
class EventsAPIController < AppController
def show
@event = Event.find(params[:id])
# scroll down to see how we can improve this line
EventView.create(user: current_user)
render json: @event
end
end
How code above can be improved (and by improved I mean faster)? This API endpoint is responsible to return JSON info about Event.
What in this code can slowdown this API?
Probably this: EventView.create(user: current_user)
? This is the only one write operation that we have.
Now, imagine that in our app we have background jobs. We can start a new background job to create event in async mode. But what could be even simpler? Correct answer is to use this gem :) With help of this gem you can rewrite your code to this:
#
# improved version, it will work 100% faster
#
class EventsAPIController < AppController
def show
@event = Event.find(params[:id])
EventView.create_async(user: current_user) # <--- here is a change
render json: @event
end
end
When we call .create_async
, it will start a new background job and create new record in the background.
You have methods like:
.create_async
.save_async
.update_async
.destroy_async
# create
User.create_async(first_name: "John", last_name: "Smith")
# update
@user.update_async(first_name: "New Name")
# save
@user.first_name = "New Name"
@user.save_async
# destroy
@user.destroy_async
Ideal use case - when you just need to do an atomic action that won't require any logic with object.
if @user.save_async
... # this won't work as expected
else
... # sorry validation happens only in the background
end
@user = User.create_async(attrs)
puts @user.full_name # this code won't work
Add this line to your application's Gemfile:
gem "create_update_destroy_async"
And then execute:
$ bundle
rails s -e production
wrk -c100 http://127.0.0.1:3000/home/index1
rails s -e production
wrk -c100 http://127.0.0.1:3000/home/index2
You can start rails s in dummy app, and open http://localhost:3000/home/index1 and http://localhost:3000/home/index2.
In addition you need to start Sidekiq in the background.
You are welcome to contribute.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that create_update_destroy_async demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.