DEV: Skip unnecessary work when booting dev server on linux (#28401)

The Listen gem watches recursively, which has a cost per-file on Linux (via rb-inotify). This commit skips a bunch of unnecessary directories to reduce the startup cost.
This commit is contained in:
David Taylor 2024-08-16 16:05:41 +01:00 committed by GitHub
parent 9c1812e071
commit e8308f783d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,21 @@ if Rails.env.development? && !Rails.configuration.cache_classes && Discourse.run
"#{Rails.root}/plugins",
]
if Listen::Adapter::Linux.usable?
# The Listen gem watches recursively, which has a cost per-file on Linux (via rb-inotify)
# Skip a bunch of unnecessary directories to reduce the cost
# Ref https://github.com/guard/listen/issues/556
require "rb-inotify"
INotify::Notifier.prepend(
Module.new do
def watch(path, *flags, &callback)
return if path.end_with?("/node_modules", "/.git")
super(path, *flags, &callback)
end
end,
)
end
Listen
.to(*paths, only: /\.rb$/) do |modified, added, removed|
supervisor_pid = UNICORN_DEV_SUPERVISOR_PID