Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/entitlements/backend/github_team/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ def initialize(group_name, config = nil)

def prefetch
teams = Entitlements::Data::Groups::Calculated.read_all(group_name, config)
teams.each do |team_slug|
entitlement_group = Entitlements::Data::Groups::Calculated.read(team_slug)
provider.read(entitlement_group)
end
entitlement_groups = teams.map { |team_slug| Entitlements::Data::Groups::Calculated.read(team_slug) }
provider.prefetch(entitlement_groups)
end

# Calculation routines.
Expand Down
29 changes: 23 additions & 6 deletions lib/entitlements/backend/github_team/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ def initialize(config:)
@github_team_cache = {}
end

# Populate the provider cache for a collection of desired teams.
#
# entitlement_groups - Array of Entitlements::Models::Group objects.
#
# Returns nothing.
Contract C::ArrayOf[Entitlements::Models::Group] => nil
def prefetch(entitlement_groups)
github.read_teams(entitlement_groups).each do |team_name, github_team|
log_loaded_team(github_team) if github_team
@github_team_cache[team_name] = github_team
end
nil
end

# Read in a specific GitHub.com Team and enumerate its members. Results are cached
# for future runs.
#
Expand All @@ -39,15 +53,12 @@ def initialize(config:)
Contract Entitlements::Models::Group => C::Maybe[Entitlements::Models::Group]
def read(entitlement_group)
slug = Entitlements::Util::Util.any_to_cn(entitlement_group.cn.downcase)
return @github_team_cache[slug] if @github_team_cache[slug]
return @github_team_cache[slug] if @github_team_cache.key?(slug)

github_team = github.read_team(entitlement_group)

# We should not cache a team which does not exist
return nil if github_team.nil?

Entitlements.logger.debug "Loaded #{github_team.team_dn} (id=#{github_team.team_id}) with #{github_team.member_strings.count} member(s)"
@github_team_cache[github_team.team_name] = github_team
log_loaded_team(github_team) if github_team
@github_team_cache[slug] = github_team
end

# Dry run of committing changes. Returns a list of users added or removed.
Expand Down Expand Up @@ -151,6 +162,12 @@ def auto_generate_ignored_users(entitlement_group)

private

Contract Entitlements::Backend::GitHubTeam::Models::Team => nil
def log_loaded_team(github_team)
Entitlements.logger.debug "Loaded #{github_team.team_dn} (id=#{github_team.team_id}) with #{github_team.member_strings.count} member(s)"
nil
end

# Construct an Entitlements::Models::Group for a new group and team
#
# group - An Entitlements::Models::Group object representing the defined group
Expand Down
Loading
Loading