Skip to content

Commit

Permalink
Merge pull request #559 from fatkodima/memory_optimizations
Browse files Browse the repository at this point in the history
Reduce memory allocated when rendering the index page
  • Loading branch information
danmayer authored Oct 16, 2024
2 parents 8a9b4e4 + f60ebd6 commit 4b408af
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lib/coverband/collectors/abstract_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def newly_seen_key?(key)
end

def track_key?(key, options = {})
@ignore_patterns.none? { |pattern| key.to_s.include?(pattern) }
key = key.to_s
@ignore_patterns.none? { |pattern| key.match?(pattern) }
end

private
Expand Down
6 changes: 3 additions & 3 deletions lib/coverband/collectors/view_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def unused_keys(used_views = nil)
recently_used_views = used_keys.keys
unused_views = all_keys - recently_used_views
# since layouts don't include format we count them used if they match with ANY formats
unused_views.reject { |view| view.match(/\/layouts\//) && recently_used_views.any? { |used_view| view.include?(used_view) } }
unused_views.reject { |view| @ignore_patterns.any? { |pattern| view.include?(pattern) } }
unused_views.reject { |view| view.include?("/layouts/") && recently_used_views.any? { |used_view| view.include?(used_view) } }
unused_views.reject { |view| @ignore_patterns.any? { |pattern| view.match?(pattern) } }
end

def clear_key!(filename)
Expand All @@ -100,7 +100,7 @@ def clear_key!(filename)

def track_file?(file, options = {})
(file.start_with?(@project_directory) || options[:layout]) &&
@ignore_patterns.none? { |pattern| file.include?(pattern) }
@ignore_patterns.none? { |pattern| file.match?(pattern) }
end

def concrete_target
Expand Down
6 changes: 3 additions & 3 deletions lib/coverband/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def initialize
def reset
@root = Dir.pwd
@root_paths = []
@ignore = IGNORE_DEFAULTS.dup
@ignore = IGNORE_DEFAULTS.map { |ignore_str| Regexp.new(ignore_str) }
@search_paths = TRACKED_DEFAULT_PATHS.dup
@verbose = false
@reporter = "scov"
Expand Down Expand Up @@ -222,8 +222,8 @@ def search_paths=(path_array)
# Don't allow the ignore to override things like gem tracking
###
def ignore=(ignored_array)
ignored_array.map { |ignore_str| Regexp.new(ignore_str) }
@ignore = (@ignore + ignored_array).uniq
ignored_array = ignored_array.map { |ignore_str| Regexp.new(ignore_str) }
@ignore |= ignored_array
rescue RegexpError
logger.error "an invalid regular expression was passed in, ensure string are valid regex patterns #{ignored_array.join(",")}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/coverband/reporters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def fix_reports(reports)

# apply coverband filters
report_files.each_pair do |file, data|
next if Coverband.configuration.ignore.any? { |i| file.match(i) }
next if Coverband.configuration.ignore.any? { |i| file.match?(i) }

filtered_report_files[report_name][file] = data
end
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_current_scov_data_imp(store, roots, options = {})
scov_style_report = {}
store.get_coverage_report(options).each_pair do |name, data|
data.each_pair do |key, line_data|
next if Coverband.configuration.ignore.any? { |i| key.match(i) }
next if Coverband.configuration.ignore.any? { |i| key.match?(i) }
next unless line_data

scov_style_report[name] = {} unless scov_style_report.key?(name)
Expand Down
7 changes: 4 additions & 3 deletions lib/coverband/utils/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def no_lines?
end

def lines_strength
lines.map(&:coverage).compact.reduce(:+)
lines.sum do |line|
line.coverage || 0
end
end

def relevant_lines
Expand Down Expand Up @@ -256,8 +258,7 @@ def process_skipped_lines(lines)
# was at the start of the file name
# I had previously patched this in my local Rails app
def short_name
filename.sub(/^#{Coverband.configuration.root}/, ".")
.gsub(%r{^\.\/}, "")
filename.delete_prefix("#{Coverband.configuration.root}/")
end

def relative_path
Expand Down
6 changes: 3 additions & 3 deletions test/coverband/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setup

test "ignore works with equal" do
Coverband::Collectors::Coverage.instance.reset_instance
expected = ["vendor/", ".erb$", ".slim$", "/tmp", "internal:prelude", "db/schema.rb", "config/environments"]
expected = ["vendor/", ".erb$", ".slim$", "/tmp", "internal:prelude", "db/schema.rb", "config/environments"].map { |str| Regexp.new(str) }
assert_equal expected, Coverband.configuration.ignore
end

Expand All @@ -34,7 +34,7 @@ def setup
"internal:prelude",
"db/schema.rb",
"config/environments",
"config/initializers"]
"config/initializers"].map { |str| Regexp.new(str) }
assert_equal expected, Coverband.configuration.ignore
end

Expand All @@ -44,7 +44,7 @@ def setup
config.ignore = ["*invalidRegex*"]
end
Coverband::Collectors::Coverage.instance.reset_instance
expected = Coverband::Configuration::IGNORE_DEFAULTS << "config/environments"
expected = (Coverband::Configuration::IGNORE_DEFAULTS << "config/environments").map { |str| Regexp.new(str) }
assert_equal expected, Coverband.configuration.ignore
end

Expand Down

0 comments on commit 4b408af

Please sign in to comment.