Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Repo Requests in Parallel on ProjectDetail Pages #1562

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

ghickman
Copy link
Contributor

On ProjectDetail pages with several repos the lookup for private/public
status was noticably slowing the page down. This switches to
ThreadPoolExecutor to run through them in parallel (mostly).

@ghickman ghickman force-pushed the optimise-project-detail branch 2 times, most recently from dc2543c to 5897d25 Compare January 27, 2022 11:20
@ghickman
Copy link
Contributor Author

@bloodearnest – is this good to go now?

Copy link
Member

@bloodearnest bloodearnest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 with a suggestion

"name": f.path.segments[1],
"url": url,
"is_private": is_private,
}

futures = [repo_thread_pool.submit(get_repo, url=url) for url in repo_urls]
for future in concurrent.futures.as_completed(futures):
Copy link
Member

@bloodearnest bloodearnest Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I think we can slightly simplify this using Executor.map(). We can also set an explicit timeout for all requests too, which is usually a good idea when doing concurrency.

So, maybe replace the last 3 lines with:

# use the threadpool to parallelise the repo requests
yield from repo_thread_pool.map(get_repo, repo_urls, timeout=30)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map basically does what you did, but handles cancellation and timeouts: https://github.com/python/cpython/blob/main/Lib/concurrent/futures/_base.py#L571

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer, and TIL!

On ProjectDetail pages with several repos the lookup for private/public
status was noticably slowing the page down.  This switches to
ThreadPoolExecutor to run through them in parallel (mostly).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants