Skip to content

Commit 7b70b69

Browse files
author
Alex Evanczuk
authored
bin/codeownership for_team should use cache (90% perf improvement) (#56)
1 parent 951c21a commit 7b70b69

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
code_ownership (1.32.10)
4+
code_ownership (1.32.11)
55
code_teams (~> 1.0)
66
packs
77
sorbet-runtime

code_ownership.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'code_ownership'
3-
spec.version = '1.32.10'
3+
spec.version = '1.32.11'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['[email protected]']
66
spec.summary = 'A gem to help engineering teams declare ownership of code'

lib/code_ownership.rb

+7-11
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,23 @@ def for_file(file)
4343

4444
sig { params(team: T.any(CodeTeams::Team, String)).returns(String) }
4545
def for_team(team)
46-
Private.load_configuration!
47-
4846
team = T.must(CodeTeams.find(team)) if team.is_a?(String)
4947
ownership_information = T.let([], T::Array[String])
5048

5149
ownership_information << "# Code Ownership Report for `#{team.name}` Team"
52-
Mapper.all.each do |mapper|
53-
ownership_information << "## #{mapper.description}"
54-
codeowners_lines = mapper.globs_to_owner(Private.tracked_files)
50+
51+
Private.glob_cache.raw_cache_contents.each do |mapper_description, glob_to_owning_team_map|
52+
ownership_information << "## #{mapper_description}"
5553
ownership_for_mapper = []
56-
codeowners_lines.each do |line, team_for_line|
57-
next if team_for_line.nil?
58-
if team_for_line.name == team.name
59-
ownership_for_mapper << "- #{line}"
60-
end
54+
glob_to_owning_team_map.each do |glob, owning_team|
55+
next if owning_team != team
56+
ownership_for_mapper << "- #{glob}"
6157
end
6258

6359
if ownership_for_mapper.empty?
6460
ownership_information << 'This team owns nothing in this category.'
6561
else
66-
ownership_information += ownership_for_mapper
62+
ownership_information += ownership_for_mapper.sort
6763
end
6864

6965
ownership_information << ""

lib/code_ownership/mapper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ def self.to_glob_cache
6868

6969
Mapper.all.each do |mapper|
7070
mapped_files = mapper.globs_to_owner(Private.tracked_files)
71+
glob_to_owner_map_by_mapper_description[mapper.description] ||= {}
72+
7173
mapped_files.each do |glob, owner|
7274
next if owner.nil?
73-
glob_to_owner_map_by_mapper_description[mapper.description] ||= {}
7475
glob_to_owner_map_by_mapper_description.fetch(mapper.description)[glob] = owner
7576
end
7677
end

0 commit comments

Comments
 (0)