Skip to content

Commit 653c56b

Browse files
committed
fix for finding the eager loading data without iterating through files 2*N
1 parent 2c6b6e0 commit 653c56b

File tree

6 files changed

+62
-7
lines changed

6 files changed

+62
-7
lines changed

changes.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Coverband 6.1.1
2+
3+
* Performance fix making paged report loading 10X faster
4+
15
### Coverband 6.1.0
26

37
This release has a number of smaller fixes and improvements. It includes a sizable refactoring around the UI which should simplify improvements going forward. This release is mostly targetting large projects with 6K+ ruby files, use the new `config.paged_reporting = true` option with the HashRedisStore to enable paged reporting for large projects. The HashRedisStore now also includes the last time a line in a file was executed.

coverband.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
3636
spec.add_development_dependency "memory_profiler"
3737
# breaking change in minitest and mocha...
3838
# note: we are also adding 'spy' as mocha doesn't want us to spy on redis calls...
39+
spec.add_development_dependency "spy"
3940
# ^^^ probably need a large test cleanup refactor
4041
spec.add_development_dependency "minitest", "= 5.18.1"
4142
spec.add_development_dependency "minitest-fork_executor"

lib/coverband/adapters/hash_redis_store.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,22 @@ def coverage_for_types(_types, opts = {})
231231
end
232232
end
233233

234+
# NOTE: This is kind of hacky, we find all the matching eager loading data
235+
# for current page of runtime data.
234236
eager_key_pre = key_prefix(Coverband::EAGER_TYPE)
235237
runtime_key_pre = key_prefix(Coverband::RUNTIME_TYPE)
236-
matched_file_set = files_set(Coverband::EAGER_TYPE)
237-
.select do |eager_key, _val|
238-
runtime_file_set.any? do |runtime_key|
239-
(eager_key.sub(eager_key_pre, "") == runtime_key.sub(runtime_key_pre, ""))
240-
end
241-
end || []
238+
matched_file_set = runtime_file_set.map do |runtime_key|
239+
runtime_key.sub(runtime_key_pre, eager_key_pre)
240+
end
241+
242242
hash_data[Coverband::EAGER_TYPE] = matched_file_set.each_slice(page_size).flat_map do |key_batch|
243243
@redis.pipelined do |pipeline|
244244
key_batch.each do |key|
245245
pipeline.hgetall(key)
246246
end
247247
end
248248
end
249+
249250
hash_data[Coverband::RUNTIME_TYPE] = hash_data[Coverband::RUNTIME_TYPE].each_with_object({}) do |data_from_redis, hash|
250251
add_coverage_for_file(data_from_redis, hash)
251252
end

lib/coverband/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
# use format "4.2.1.rc.1" ~> 4.2.1.rc to prerelease versions like v4.2.1.rc.2 and v4.2.1.rc.3
66
###
77
module Coverband
8-
VERSION = "6.1.0"
8+
VERSION = "6.1.1"
99
end

test/coverband/adapters/hash_redis_store_test.rb

+48
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,52 @@ def test_get_coverage_cache
242242
@store.coverage["./dog.rb"]
243243
)
244244
end
245+
246+
def test_split_coverage
247+
@store = Coverband::Adapters::HashRedisStore.new(
248+
@redis,
249+
redis_namespace: "coverband_test",
250+
relative_file_converter: MockRelativeFileConverter
251+
)
252+
253+
mock_file_hash
254+
yesterday = DateTime.now.prev_day.to_time
255+
mock_time(yesterday)
256+
257+
@store.type = :eager_loading
258+
data = {
259+
"app_path/dog.rb" => [0, nil, 1]
260+
}
261+
@store.save_report(data)
262+
263+
@store.type = :runtime
264+
@store.save_report(
265+
"app_path/dog.rb" => [0, 1, 2]
266+
)
267+
redis_pipelined = Spy.on(@redis, :pipelined).and_call_through
268+
assert_equal(
269+
{
270+
runtime: {
271+
"./dog.rb" => {
272+
"first_updated_at" => yesterday.to_i,
273+
"last_updated_at" => yesterday.to_i,
274+
"file_hash" => "abcd",
275+
"data" => [0, 1, 2],
276+
"timedata" => [nil, Time.at(yesterday.to_i), Time.at(yesterday.to_i)]
277+
}
278+
},
279+
eager_loading: {
280+
"./dog.rb" => {
281+
"first_updated_at" => yesterday.to_i,
282+
"last_updated_at" => nil,
283+
"file_hash" => "abcd",
284+
"data" => [0, nil, 1],
285+
"timedata" => [nil, nil, Time.at(yesterday.to_i)]
286+
}
287+
}
288+
},
289+
@store.split_coverage([Coverband::RUNTIME_TYPE, Coverband::EAGER_TYPE], {}, {page: 1})
290+
)
291+
assert_equal 2, redis_pipelined.calls.count
292+
end
245293
end

test/test_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
require "coverband/reporters/html_report"
3636
require "coverband/reporters/json_report"
3737
require "webmock/minitest"
38+
require "spy/integration"
3839

3940
require_relative "unique_files"
4041
$VERBOSE = original_verbosity

0 commit comments

Comments
 (0)