diff options
author | Nick Thomas <nick@gitlab.com> | 2017-08-23 15:28:16 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-08-25 16:19:32 +0100 |
commit | 8b73df0cf534797bff9ce0f5b95af5347ea59ca6 (patch) | |
tree | 9dea336cc8619391dbdf6c904a3f72e873c37090 /app/services | |
parent | 24244d03b55bc7732b3362bab1e1cc7e04c2dabf (diff) | |
download | gitlab-ce-8b73df0cf534797bff9ce0f5b95af5347ea59ca6.tar.gz |
Move sidekiq-based project authorization refresh out of Projects::CreateService
If the project is in a group, the `group.refresh_members_authorized_projects`
is made non-blocking, and we call `current_user.refresh_authorized_projects`
directly.
Projects in a personal namespace are more difficult. Rather than passing the
`blocking:` parameter through the entire `add_master` chain, have the
`AuthorizedProjectsWorker` automatically inline authorizations for three IDs or
less. Since the maximum number of IDs in this path is 2, that has the same effect.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/create_service.rb | 16 | ||||
-rw-r--r-- | app/services/user_project_access_changed_service.rb | 10 |
2 files changed, 21 insertions, 5 deletions
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 48578b6d9e5..0d6066b70c7 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -99,12 +99,22 @@ module Projects event_service.create_project(@project, current_user) system_hook_service.execute_hooks_for(@project, :create) - unless @project.group || @project.gitlab_project_import? + setup_authorizations + 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 + def setup_authorizations + group = @project.group + group&.refresh_members_authorized_projects(blocking: false) + + if group || @project.gitlab_project_import? + current_user.refresh_authorized_projects + else owners = [current_user, @project.namespace.owner].compact.uniq @project.add_master(owners, current_user: current_user) end - - @project.group&.refresh_members_authorized_projects end def skip_wiki? diff --git a/app/services/user_project_access_changed_service.rb b/app/services/user_project_access_changed_service.rb index d7a6804ee88..8630e572624 100644 --- a/app/services/user_project_access_changed_service.rb +++ b/app/services/user_project_access_changed_service.rb @@ -3,7 +3,13 @@ class UserProjectAccessChangedService @user_ids = Array.wrap(user_ids) end - def execute - AuthorizedProjectsWorker.bulk_perform_and_wait(@user_ids.map { |id| [id] }) + def execute(blocking: true) + bulk_args = @user_ids.map { |id| [id] } + + if blocking + AuthorizedProjectsWorker.bulk_perform_and_wait(bulk_args) + else + AuthorizedProjectsWorker.bulk_perform_async(bulk_args) + end end end |