DEV: Use fewer threads when watching for SCSS changes (#12393)

This commit is contained in:
Penar Musaraj 2021-03-12 16:18:00 -05:00 committed by GitHub
parent 2a18b0b07e
commit de05c410c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 49 deletions

View File

@ -27,24 +27,20 @@ module Stylesheet
end
def start
Thread.new do
begin
while true
worker_loop
end
rescue => e
STDERR.puts "CSS change notifier crashed #{e}"
STDERR.puts "CSS change notifier crashed \n#{e}"
start
end
end
root = Rails.root.to_s
listener_opts = { ignore: /xxxx/ }
listener_opts = { ignore: /xxxx/, only: /\.(css|scss)$/ }
listener_opts[:force_polling] = true if ENV['FORCE_POLLING']
@paths.each do |watch|
Thread.new do
begin
plugins_paths = Dir.glob("#{Rails.root}/plugins/*").map do |file|
@ -55,7 +51,7 @@ module Stylesheet
end
end.compact
listener = Listen.to("#{root}/#{watch}", listener_opts) do |modified, added, _|
listener = Listen.to(*@paths, listener_opts) do |modified, added, _|
paths = [modified, added].flatten
paths.compact!
paths.map! do |long|
@ -83,13 +79,12 @@ module Stylesheet
process_change(paths)
end
rescue => e
STDERR.puts "Failed to listen for CSS changes at: #{watch}\n#{e}"
STDERR.puts "Failed to listen for CSS changes: \n#{e}"
end
listener.start
sleep
end
end
end
def core_assets_refresh(target)
targets = target ? [target] : ["desktop", "mobile", "admin"]
@ -138,11 +133,9 @@ module Stylesheet
def process_change(paths)
paths.each do |path|
if path[:basename] =~ /\.(css|scss)$/
@queue.push path
end
end
end
def active_themes
@active_themes ||= Theme.user_selectable.pluck(:id)