Improve performance and simplify WorkspaceCreate
view
#4685
Labels
deck-scrubbing
Tech debt or other between-initiative tidy-up work
WorkspaceCreate
view
#4685
The
WorkspaceCreate
view (/{project_name}/new-workspace/
) takes 5-10s to load, both on initial visit and when submitting the form. This is poor UX and will worsen over time as more repos and branches are created in the opensafely GitHub organization. It would be good to improve this if not too expensive. In mitigation, new workspaces are only occasionally created (there are ~500 in prod over 3.5 years).Analysis
Almost all of the execution time comes from
github.get_repos_with_branches
. The form does need the list of repos to populate the repo selector. And the branches for the repo that is selected. But it doesn't need to know all of the branches. It should be quicker to fetch just the repos list initially, then the branches for a single repo as needed.Ad hoc testing with curl should it takes about a second to get the list of repos, and less than 0.5s to get one branch:
Wizard solution
A "wizard" refers to a multi-step form process that guides users through a series of steps or stages to complete a task. We've not used these so far but they could perform better and be simpler to maintain than the current approach.
The repo selector could be on a separate page. Then the initial form needs the repo list, and the separate page needs the branches for the selected repo.
Could use Django's built-in FormView and manage state between steps e.g in the session, or django-formtools library's WizardView. Or HTMX for a single-page multi-part wizard?
Single-page solution
Sketch:
github.get_repos
to get the list of repos in the opensafely organization and populate the reposChoiceField
. Cache it for theclean
.github.get_branches
to populate the initial branches field. Or pseudo-cache it in the POST data payload. Cache it for theclean
.github.get_branches
as a JSON data endpoint.workspace_create.js
makes an AJAX request to the new endpoint when the repo selector changes, instead of looking up in therepos_with_branches
currently embedded in the HTML page.clean
uses the cached repos and branches for validation, or callsgithub.get_branches
if it has changed.github.get_repos_with_branches
.Possibly this would be better with HTMX?
Other options
github.get_repos_with_branches
. I haven't fully understood why it is slow. It's written with GraphQL with performance in mind. Not clear there are improvements to make. The remote GitHub API may not provide a more efficient way to get all the data.The text was updated successfully, but these errors were encountered: