Skip to content
Draft
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: 6 additions & 0 deletions lib/entitlements/backend/github_org/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ def validate_config!(key, data)
end
end

# Pre-fetch the current state of the organization from the API. Both of these are memoized
# by the provider, so calling them here means `calculate` reuses the result instead of
# making the request itself. Entitlements runs `prefetch` for every group through a thread
# pool sized by `max_parallelism`, whereas `calculate` runs serially, so fetching here lets
# these requests overlap across organizations.
def prefetch
existing_groups
provider.pending_members
end

private
Expand Down
5 changes: 4 additions & 1 deletion spec/unit/entitlements/backend/github_org/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@

service = subject.send(:provider).github
expect(service).to receive(:members_and_roles_from_rest).and_return(answer2)
expect(service).to receive(:pending_members).exactly(2).times.and_return(Set.new)
expect(service).to receive(:pending_members).exactly(3).times.and_return(Set.new)

expect(logger).to receive(:debug).with("Loading organization members and roles for kittensinc from cache")
expect(logger).to receive(:debug).with("Currently kittensinc has 1 admin(s) and 2 member(s)")
Expand Down Expand Up @@ -845,6 +845,7 @@

github_double = instance_double(Entitlements::Backend::GitHubOrg::Provider)
allow(subject).to receive(:provider).and_return(github_double)
allow(github_double).to receive(:pending_members).and_return(Set.new)
allow(github_double).to receive(:read).with("cn=member,ou=kittensinc,ou=GitHub,dc=github,dc=com").and_return({})
allow(github_double).to receive(:read).with("cn=admin,ou=kittensinc,ou=GitHub,dc=github,dc=com").and_return({})

Expand All @@ -868,6 +869,7 @@

github_double = instance_double(Entitlements::Backend::GitHubOrg::Provider)
allow(subject).to receive(:provider).and_return(github_double)
allow(github_double).to receive(:pending_members).and_return(Set.new)
dns.each do |dn|
allow(github_double).to receive(:read).with(dn).and_return({})
end
Expand Down Expand Up @@ -911,6 +913,7 @@

github_double = instance_double(Entitlements::Backend::GitHubOrg::Provider)
allow(subject).to receive(:provider).and_return(github_double)
allow(github_double).to receive(:pending_members).and_return(Set.new)
allow(github_double).to receive(:read).with(admin_dn).and_return(admin_group)
allow(github_double).to receive(:read).with(member_dn).and_return(member_group)

Expand Down
Loading