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
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!
Top comments (0)