Skip to content

Commit

Permalink
Sychronize cache sweeper action to prevent race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed May 18, 2024
1 parent 59406ab commit 0e9e914
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 @@ -38,9 +38,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 @@ -69,6 +73,10 @@ def clear_cache
@cached_assets_by_path = 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 0e9e914

Please sign in to comment.