Inform user which directories are contributing to overloading the fuzzy file finder
This commit is contained in:
parent
8a69715313
commit
43a7a2de36
18
lib/diakonos/vendor/fuzzy_file_finder.rb
vendored
18
lib/diakonos/vendor/fuzzy_file_finder.rb
vendored
|
@ -128,6 +128,7 @@ class FuzzyFileFinder
|
||||||
|
|
||||||
@files = []
|
@files = []
|
||||||
@directories = {} # To detect link cycles
|
@directories = {} # To detect link cycles
|
||||||
|
@dirs_with_many = []
|
||||||
|
|
||||||
rescan!
|
rescan!
|
||||||
end
|
end
|
||||||
|
@ -222,9 +223,22 @@ class FuzzyFileFinder
|
||||||
if ! @directories[real_dir]
|
if ! @directories[real_dir]
|
||||||
@directories[real_dir] = true
|
@directories[real_dir] = true
|
||||||
|
|
||||||
Dir.entries(directory.name).each do |entry|
|
Dir.entries(directory.name)
|
||||||
|
.tap { |_entries|
|
||||||
|
if _entries.length > ceiling/10
|
||||||
|
@dirs_with_many << [_entries.length, directory.name]
|
||||||
|
$diakonos.log "[#{self.class}] Many dir entries: #{_entries.length} in #{directory.name}"
|
||||||
|
end
|
||||||
|
}.each do |entry|
|
||||||
next if entry[0,1] == "."
|
next if entry[0,1] == "."
|
||||||
raise TooManyEntries if files.length > ceiling
|
if files.length > ceiling
|
||||||
|
raise TooManyEntries.new(%{
|
||||||
|
Directories with many entries:
|
||||||
|
|
||||||
|
#{@dirs_with_many.map { |d| d.join("\t") }.join("\n")}
|
||||||
|
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
full = File.join(directory.name, entry)
|
full = File.join(directory.name, entry)
|
||||||
next if ignore?(full)
|
next if ignore?(full)
|
||||||
|
|
|
@ -12,7 +12,8 @@ RSpec.describe FuzzyFileFinder do
|
||||||
let(:finder) { described_class.new(params) }
|
let(:finder) { described_class.new(params) }
|
||||||
|
|
||||||
let(:ceiling) { nil }
|
let(:ceiling) { nil }
|
||||||
let(:directories) { ['spec/test-files'] }
|
let(:root_dir) { "spec/test-files" }
|
||||||
|
let(:directories) { [root_dir] }
|
||||||
let(:ignores) { [] }
|
let(:ignores) { [] }
|
||||||
let(:recursive) { nil }
|
let(:recursive) { nil }
|
||||||
|
|
||||||
|
@ -33,5 +34,14 @@ RSpec.describe FuzzyFileFinder do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when the ceiling is less than the number of entries searched" do
|
||||||
|
let(:ceiling) { 5 }
|
||||||
|
|
||||||
|
it "raises a TooManyEntries exception" do
|
||||||
|
expect { finder.find(input) }
|
||||||
|
.to raise_exception(FuzzyFileFinder::TooManyEntries, %r[14.*#{root_dir}])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue