A platform for community discussion. Free, open, simple.
DEV: Use fewer threads when watching for SCSS changes (#12393)
Penar Musarajde05c410c549
diff --git a/lib/stylesheet/watcher.rb b/lib/stylesheet/watcher.rbindex 1b83891affb..f814d1b782d 100644--- a/lib/stylesheet/watcher.rb+++ b/lib/stylesheet/watcher.rb@@ -27,67 +27,62 @@ module Stylesheetenddef start-Thread.new dobeginwhile trueworker_loopendrescue => e- STDERR.puts "CSS change notifier crashed #{e}"+ STDERR.puts "CSS change notifier crashed \n#{e}"startendend- 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|- if File.symlink?(file)- File.expand_path(File.readlink(file), "#{Rails.root}/plugins")- else- file- end- end.compact-- listener = Listen.to("#{root}/#{watch}", listener_opts) do |modified, added, _|- paths = [modified, added].flatten- paths.compact!- paths.map! do |long|- plugin_name = nil- plugins_paths.each do |plugin_path|- if long.include?("#{plugin_path}/")- plugin_name = File.basename(plugin_path)- break- end- end-- target = nil- target_match = long.match(/admin|desktop|mobile|publish/)- if target_match&.length- target = target_match[0]+ Thread.new do+ begin+ plugins_paths = Dir.glob("#{Rails.root}/plugins/*").map do |file|+ if File.symlink?(file)+ File.expand_path(File.readlink(file), "#{Rails.root}/plugins")+ else+ file+ end+ end.compact++ listener = Listen.to(*@paths, listener_opts) do |modified, added, _|+ paths = [modified, added].flatten+ paths.compact!+ paths.map! do |long|+ plugin_name = nil+ plugins_paths.each do |plugin_path|+ if long.include?("#{plugin_path}/")+ plugin_name = File.basename(plugin_path)+ breakend+ end- {- basename: File.basename(long),- target: target,- plugin_name: plugin_name- }+ target = nil+ target_match = long.match(/admin|desktop|mobile|publish/)+ if target_match&.length+ target = target_match[0]end- process_change(paths)+ {+ basename: File.basename(long),+ target: target,+ plugin_name: plugin_name+ }end- rescue => e- STDERR.puts "Failed to listen for CSS changes at: #{watch}\n#{e}"++ process_change(paths)end- listener.start- sleep+ rescue => e+ STDERR.puts "Failed to listen for CSS changes: \n#{e}"end+ listener.start+ sleependend@@ -138,9 +133,7 @@ module Stylesheetdef process_change(paths)paths.each do |path|- if path[:basename] =~ /\.(css|scss)$/- @queue.push path- end+ @queue.push pathendend