Commit d80008bf authored by Sean McGivern's avatar Sean McGivern

Speed up project creation for users with many projects

When a user creates a project in a group, we refresh the
`authorized_projects` table for all members of that group using Sidekiq.
This includes the user that created the project, but that alone would
mean that if the Sidekiq job didn't finish almost immediately, a user
could create a project that they'd be unable to see for a few seconds.

We solved this by immediately refreshing all the projects for the user
who created the project. However, that in turn can be quite slow,
because we need to recompute the entire project authorization structure
for a user.

This commit changes that to just insert a single row to
`authorized_projects` for the user who created the project. It should be
accurate all the time, but if it is not quite right, the Sidekiq job
will correct it shortly after anyway.
parent 63ba19d7
......@@ -107,12 +107,13 @@ module Projects
create_readme if @initialize_with_readme
end
# Refresh the current user's authorizations inline (so they can access the
# project immediately after this request completes), and any other affected
# users in the background
# Add an authorization for the current user authorizations inline
# (so they can access the project immediately after this request
# completes), and any other affected users in the background
def setup_authorizations
if @project.group
current_user.refresh_authorized_projects
current_user.project_authorizations.create!(project: @project,
access_level: @project.group.max_member_access_for_user(current_user))
if Feature.enabled?(:specialized_project_authorization_workers)
AuthorizedProjectUpdate::ProjectCreateWorker.perform_async(@project.id)
......
---
title: Speed up project creation for users with many projects
merge_request:
author:
type: performance
......@@ -676,10 +676,6 @@ RSpec.describe Projects::CreateService, '#execute' do
end
it 'updates authorization for current_user' do
expect(Users::RefreshAuthorizedProjectsService).to(
receive(:new).with(user).and_call_original
)
project = create_project(user, opts)
expect(
......@@ -711,10 +707,6 @@ RSpec.describe Projects::CreateService, '#execute' do
end
it 'updates authorization for current_user' do
expect(Users::RefreshAuthorizedProjectsService).to(
receive(:new).with(user).and_call_original
)
project = create_project(user, opts)
expect(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment