DEV Community

Cover image for Skip turbo broadcasting to speed up seeding process in Rails
Edwin Mak
Edwin Mak

Posted on

2

Skip turbo broadcasting to speed up seeding process in Rails

Introduction

We discovered that our seeding process for our rails application was getting very slow by turbo broadcasting via callbacks triggered by saving models. Although this works as intended, we certainly don't need to broadcast turbo frames in the seeding process and just serves to slow down the seeding process without any benefits.

Solution

We were able to speed up the seeding process by 3x (~140s to ~40s) by disabling turbo broadcasting in seeding. You can disable them too by inserting this code snippet before your seeding process:

class Turbo::StreamsChannel
  [:broadcast_append_to, :broadcast_prepend_to, :broadcast_replace_to, :broadcast_remove_to].each do |method|
    define_singleton_method(method) do |*args|
      return nil
    end
  end
end

# SEEDING PROCESS BEGINS
Enter fullscreen mode Exit fullscreen mode

Conclusion

We were able to improve the developer experience by making the
seeding process quicker with a short snippet of code. Shaving off about a minute of seeding seems insignificant, but it adds up!

Hope this helps!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay