~pistos/diakonos

43a7a2de36f4af0beea47eb08d14ceed9b3342a2 — Pistos 4 months ago 8a69715
Inform user which directories are contributing to overloading the fuzzy file finder
2 files changed, 27 insertions(+), 3 deletions(-)

M lib/diakonos/vendor/fuzzy_file_finder.rb
M spec/fuzzy_file_finder_spec.rb
M lib/diakonos/vendor/fuzzy_file_finder.rb => lib/diakonos/vendor/fuzzy_file_finder.rb +16 -2
@@ 128,6 128,7 @@ class FuzzyFileFinder

    @files = []
    @directories = {}  # To detect link cycles
    @dirs_with_many = []

    rescan!
  end


@@ 222,9 223,22 @@ class FuzzyFileFinder
      if ! @directories[real_dir]
        @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] == "."
          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)
          next  if ignore?(full)

M spec/fuzzy_file_finder_spec.rb => spec/fuzzy_file_finder_spec.rb +11 -1
@@ 12,7 12,8 @@ RSpec.describe FuzzyFileFinder do
  let(:finder) { described_class.new(params) }

  let(:ceiling) { nil }
  let(:directories) { ['spec/test-files'] }
  let(:root_dir) { "spec/test-files" }
  let(:directories) { [root_dir] }
  let(:ignores) { [] }
  let(:recursive) { nil }



@@ 33,5 34,14 @@ RSpec.describe FuzzyFileFinder do
        ]
      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