Skip to content

Commit

Permalink
Merge pull request rails#53680 from jdelStrother/file-update-checker
Browse files Browse the repository at this point in the history
Make FileUpdateChecker faster with many extensions
  • Loading branch information
byroot authored Nov 22, 2024
2 parents 5d05082 + cea7280 commit b7165a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@

*Taketo Takashima*

* Make `ActiveSupport::FileUpdateChecker` faster when checking many file-extensions.

*Jonathan del Strother*

Please check [8-0-stable](https://github.com/rails/rails/blob/8-0-stable/activesupport/CHANGELOG.md) for previous changes.
7 changes: 3 additions & 4 deletions activesupport/lib/active_support/file_update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initialize(files, dirs = {}, &block)
end

@files = files.freeze
@glob = compile_glob(dirs)
@globs = compile_glob(dirs)
@block = block

@watched = nil
Expand Down Expand Up @@ -103,7 +103,7 @@ def execute_if_updated
def watched
@watched || begin
all = @files.select { |f| File.exist?(f) }
all.concat(Dir[@glob]) if @glob
all.concat(Dir[*@globs]) if @globs
all.tap(&:uniq!)
end
end
Expand Down Expand Up @@ -145,10 +145,9 @@ def compile_glob(hash)
hash.freeze # Freeze so changes aren't accidentally pushed
return if hash.empty?

globs = hash.map do |key, value|
hash.map do |key, value|
"#{escape(key)}/**/*#{compile_ext(value)}"
end
"{#{globs.join(",")}}"
end

def escape(key)
Expand Down

0 comments on commit b7165a3

Please sign in to comment.