Skip to content

Commit

Permalink
Sychronize cache sweeper action to prevent race condition (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh authored May 21, 2024
1 parent 463a502 commit 7c2ab3f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/propshaft/load_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ def cache_sweeper
@cache_sweeper ||= begin
exts_to_watch = Mime::EXTENSION_LOOKUP.map(&:first)
files_to_watch = Array(paths).collect { |dir| [ dir.to_s, exts_to_watch ] }.to_h
mutex = Mutex.new

Rails.application.config.file_watcher.new([], files_to_watch) do
clear_cache
mutex.synchronize do
clear_cache
seed_cache
end
end
end
end
Expand Down Expand Up @@ -81,6 +85,10 @@ def clear_cache
@cached_asset_paths_by_glob = nil
end

def seed_cache
assets_by_path
end

def dedup(paths)
paths = Array(paths).map { |path| Pathname.new(path) }
deduped = [].tap do |deduped|
Expand Down

0 comments on commit 7c2ab3f

Please sign in to comment.