Skip to content

Commit 5d62da9

Browse files
committed
perf: improve execution time by reducing repeated api calls
Signed-off-by: Zack Koppert <zkoppert@github.com>
1 parent 6408b99 commit 5d62da9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

measure_innersource.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ def main(): # pragma: no cover
154154
print(f"All contributors: {all_contributors}")
155155
print(f"Innersource contributors: {innersource_contributors}")
156156

157+
# Fetch all PRs and issues once
158+
print("Fetching all pull requests...")
159+
all_pulls = list(repo_data.pull_requests(state="all"))
160+
161+
print("Fetching all issues...")
162+
all_issues = list(repo_data.issues(state="all"))
163+
157164
# Count contributions for each innersource contributor
158165
innersource_contribution_counts = {}
159166
print("Counting contributions for each innersource contributor...")
@@ -169,12 +176,13 @@ def main(): # pragma: no cover
169176
):
170177
innersource_contribution_counts[contributor] += 1
171178

172-
# Add PR and issue counts
173-
for pull in repo_data.pull_requests(state="all"):
179+
# Add PR counts
180+
for pull in all_pulls:
174181
if pull.user.login == contributor:
175182
innersource_contribution_counts[contributor] += 1
176183

177-
for issue in repo_data.issues(state="all"):
184+
# Add issue counts
185+
for issue in all_issues:
178186
if hasattr(issue.user, "login") and issue.user.login == contributor:
179187
innersource_contribution_counts[contributor] += 1
180188

@@ -194,12 +202,13 @@ def main(): # pragma: no cover
194202
if hasattr(commit.author, "login") and commit.author.login == member:
195203
team_member_contribution_counts[member] += 1
196204

197-
# Add PR and issue counts
198-
for pull in repo_data.pull_requests(state="all"):
205+
# Add PR counts
206+
for pull in all_pulls:
199207
if pull.user.login == member:
200208
team_member_contribution_counts[member] += 1
201209

202-
for issue in repo_data.issues(state="all"):
210+
# Add issue counts
211+
for issue in all_issues:
203212
if hasattr(issue.user, "login") and issue.user.login == member:
204213
team_member_contribution_counts[member] += 1
205214

0 commit comments

Comments
 (0)