Skip to content

Commit

Permalink
Remove some unnecessary caching (#55)
Browse files Browse the repository at this point in the history
* Remove some unnecessary caching

* bump version
  • Loading branch information
Alex Evanczuk authored Apr 12, 2023
1 parent f1be52a commit 951c21a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
code_ownership (1.32.9)
code_ownership (1.32.10)
code_teams (~> 1.0)
packs
sorbet-runtime
Expand Down
6 changes: 3 additions & 3 deletions code_ownership.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "code_ownership"
spec.version = '1.32.9'
spec.name = 'code_ownership'
spec.version = '1.32.10'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'A gem to help engineering teams declare ownership of code'
Expand Down Expand Up @@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
spec.add_dependency 'packs'
spec.add_dependency 'sorbet-runtime'

spec.add_development_dependency 'rake'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'sorbet'
spec.add_development_dependency 'tapioca'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class FileAnnotations
extend T::Sig
include Mapper

@@map_files_to_owners = T.let({}, T.nilable(T::Hash[String, ::CodeTeams::Team])) # rubocop:disable Style/ClassVars

TEAM_PATTERN = T.let(/\A(?:#|\/\/) @team (?<team>.*)\Z/.freeze, Regexp)
DESCRIPTION = 'Annotations at the top of file'

Expand All @@ -37,9 +35,7 @@ def map_file_to_owner(file)
returns(T::Hash[String, ::CodeTeams::Team])
end
def globs_to_owner(files)
return @@map_files_to_owners if @@map_files_to_owners&.keys && @@map_files_to_owners.keys.count > 0

@@map_files_to_owners = files.each_with_object({}) do |filename_relative_to_root, mapping| # rubocop:disable Style/ClassVars
files.each_with_object({}) do |filename_relative_to_root, mapping| # rubocop:disable Style/ClassVars
owner = file_annotation_based_owner(filename_relative_to_root)
next unless owner

Expand Down Expand Up @@ -119,7 +115,6 @@ def description

sig { override.void }
def bust_caches!
@@map_files_to_owners = {} # rubocop:disable Style/ClassVars
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class PackageOwnership
extend T::Sig
include Mapper

@@package_yml_cache = T.let({}, T::Hash[String, T.nilable(Packs::Pack)]) # rubocop:disable Style/ClassVars

sig do
override.params(file: String).
returns(T.nilable(::CodeTeams::Team))
Expand Down Expand Up @@ -69,7 +67,6 @@ def owner_for_package(package)

sig { override.void }
def bust_caches!
@@package_yml_cache = {} # rubocop:disable Style/ClassVars
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions lib/code_ownership/private/ownership_mappers/team_globs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class TeamGlobs

@@map_files_to_owners = T.let(@map_files_to_owners, T.nilable(T::Hash[String, ::CodeTeams::Team])) # rubocop:disable Style/ClassVars
@@map_files_to_owners = {} # rubocop:disable Style/ClassVars
@@codeowners_lines_to_owners = T.let(@codeowners_lines_to_owners, T.nilable(T::Hash[String, ::CodeTeams::Team])) # rubocop:disable Style/ClassVars
@@codeowners_lines_to_owners = {} # rubocop:disable Style/ClassVars

sig do
params(files: T::Array[String]).
Expand Down Expand Up @@ -103,9 +101,7 @@ def update_cache(cache, files)
returns(T::Hash[String, ::CodeTeams::Team])
end
def globs_to_owner(files)
return @@codeowners_lines_to_owners if @@codeowners_lines_to_owners&.keys && @@codeowners_lines_to_owners.keys.count > 0

@@codeowners_lines_to_owners = CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars
CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars
TeamPlugins::Ownership.for(team).owned_globs.each do |owned_glob|
map[owned_glob] = team
end
Expand All @@ -114,7 +110,6 @@ def globs_to_owner(files)

sig { override.void }
def bust_caches!
@@codeowners_lines_to_owners = {} # rubocop:disable Style/ClassVars
@@map_files_to_owners = {} # rubocop:disable Style/ClassVars
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class TeamYmlOwnership

@@map_files_to_owners = T.let(@map_files_to_owners, T.nilable(T::Hash[String, ::CodeTeams::Team])) # rubocop:disable Style/ClassVars
@@map_files_to_owners = {} # rubocop:disable Style/ClassVars
@@codeowners_lines_to_owners = T.let(@codeowners_lines_to_owners, T.nilable(T::Hash[String, ::CodeTeams::Team])) # rubocop:disable Style/ClassVars
@@codeowners_lines_to_owners = {} # rubocop:disable Style/ClassVars

sig do
params(files: T::Array[String]).
Expand All @@ -39,16 +37,13 @@ def map_file_to_owner(file)
returns(T::Hash[String, ::CodeTeams::Team])
end
def globs_to_owner(files)
return @@codeowners_lines_to_owners if @@codeowners_lines_to_owners&.keys && @@codeowners_lines_to_owners.keys.count > 0

@@codeowners_lines_to_owners = CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars
CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars
map[team.config_yml] = team
end
end

sig { override.void }
def bust_caches!
@@codeowners_lines_to_owners = {} # rubocop:disable Style/ClassVars
@@map_files_to_owners = {} # rubocop:disable Style/ClassVars
end

Expand Down

0 comments on commit 951c21a

Please sign in to comment.