Performance: Sending emails from controllers
This affects server response time and user experience by potentially delaying page load while the email is sent.
def create
UserMailer.welcome_email(@user).deliver_later
redirect_to root_path
enddef create
UserMailer.welcome_email(@user).deliver_now
redirect_to root_path
end| Pattern | Server Response Time | User Wait | Impact on INP | Verdict |
|---|---|---|---|---|
| Synchronous email sending (deliver_now) | Increases by 200-500ms+ | User waits longer for page load | High negative impact | [X] Bad |
| Asynchronous email sending (deliver_later) | Minimal increase, handled in background | User sees page immediately | No impact | [OK] Good |
UserMailer and a method welcome_email?UserMailer.welcome_email(params[:user]).deliver_now after the mailer method call.def create
@user = User.new(user_params)
if @user.save
UserMailer.welcome_email(@user).deliver_later
redirect_to root_path, notice: 'User created!'deliver_later queues the email to be sent asynchronously in the background.def notify UserMailer.notify_user.deliver_now(user) redirect_to dashboard_path end
notify_user before calling deliver_now.UserMailer.notify_user(user).deliver_now.UserMailer.confirmation_email(user).deliver_now only if user.verified? is true.Pass the test and this pattern moves unknown