Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4f89acf1
Commit
4f89acf1
authored
May 27, 2021
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move bulk_stick in UserProjectAccessChangedService to Core
parent
7ff1e6f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
61 deletions
+46
-61
app/services/user_project_access_changed_service.rb
app/services/user_project_access_changed_service.rb
+13
-10
ee/app/services/ee/user_project_access_changed_service.rb
ee/app/services/ee/user_project_access_changed_service.rb
+0
-13
ee/spec/services/ee/user_project_access_changed_service_spec.rb
...c/services/ee/user_project_access_changed_service_spec.rb
+0
-38
spec/services/user_project_access_changed_service_spec.rb
spec/services/user_project_access_changed_service_spec.rb
+33
-0
No files found.
app/services/user_project_access_changed_service.rb
View file @
4f89acf1
...
...
@@ -13,17 +13,20 @@ class UserProjectAccessChangedService
def
execute
(
blocking:
true
,
priority:
HIGH_PRIORITY
)
bulk_args
=
@user_ids
.
map
{
|
id
|
[
id
]
}
if
blocking
AuthorizedProjectsWorker
.
bulk_perform_and_wait
(
bulk_args
)
else
if
priority
==
HIGH_PRIORITY
AuthorizedProjectsWorker
.
bulk_perform_async
(
bulk_args
)
# rubocop:disable Scalability/BulkPerformWithContext
result
=
if
blocking
AuthorizedProjectsWorker
.
bulk_perform_and_wait
(
bulk_args
)
else
AuthorizedProjectUpdate
::
UserRefreshWithLowUrgencyWorker
.
bulk_perform_in
(
# rubocop:disable Scalability/BulkPerformWithContext
DELAY
,
bulk_args
,
batch_size:
100
,
batch_delay:
30
.
seconds
)
if
priority
==
HIGH_PRIORITY
AuthorizedProjectsWorker
.
bulk_perform_async
(
bulk_args
)
# rubocop:disable Scalability/BulkPerformWithContext
else
AuthorizedProjectUpdate
::
UserRefreshWithLowUrgencyWorker
.
bulk_perform_in
(
# rubocop:disable Scalability/BulkPerformWithContext
DELAY
,
bulk_args
,
batch_size:
100
,
batch_delay:
30
.
seconds
)
end
end
end
::
Gitlab
::
Database
::
LoadBalancing
::
Sticking
.
bulk_stick
(
:user
,
@user_ids
)
result
end
end
UserProjectAccessChangedService
.
prepend_mod_with
(
'UserProjectAccessChangedService'
)
ee/app/services/ee/user_project_access_changed_service.rb
deleted
100644 → 0
View file @
7ff1e6f8
# frozen_string_literal: true
module
EE
module
UserProjectAccessChangedService
def
execute
(
blocking:
true
,
priority:
::
UserProjectAccessChangedService
::
HIGH_PRIORITY
)
result
=
super
::
Gitlab
::
Database
::
LoadBalancing
::
Sticking
.
bulk_stick
(
:user
,
@user_ids
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
result
end
end
end
ee/spec/services/ee/user_project_access_changed_service_spec.rb
deleted
100644 → 0
View file @
7ff1e6f8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
EE
::
UserProjectAccessChangedService
do
let
(
:service
)
{
UserProjectAccessChangedService
.
new
([
1
,
2
])
}
describe
'#execute'
do
before
do
allow
(
Gitlab
::
Database
::
LoadBalancing
).
to
receive
(
:enable?
).
and_return
(
true
)
expect
(
AuthorizedProjectsWorker
).
to
receive
(
:bulk_perform_and_wait
)
.
with
([[
1
],
[
2
]])
.
and_return
(
10
)
end
it
'sticks all the updated users and returns the original result'
,
:aggregate_failures
do
expect
(
Gitlab
::
Database
::
LoadBalancing
::
Sticking
).
to
receive
(
:bulk_stick
).
with
(
:user
,
[
1
,
2
])
expect
(
service
.
execute
).
to
eq
(
10
)
end
it
'avoids N+1 cached queries'
,
:use_sql_query_cache
,
:request_store
do
# Run this once to establish a baseline
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
do
service
.
execute
end
service
=
UserProjectAccessChangedService
.
new
([
1
,
2
,
3
,
4
,
5
])
allow
(
AuthorizedProjectsWorker
).
to
receive
(
:bulk_perform_and_wait
)
.
with
([[
1
],
[
2
],
[
3
],
[
4
],
[
5
]])
.
and_return
(
10
)
expect
{
service
.
execute
}.
not_to
exceed_all_query_limit
(
control_count
.
count
)
end
end
end
spec/services/user_project_access_changed_service_spec.rb
View file @
4f89acf1
...
...
@@ -31,4 +31,37 @@ RSpec.describe UserProjectAccessChangedService do
priority:
described_class
::
LOW_PRIORITY
)
end
end
context
'with load balancing enabled'
do
let
(
:service
)
{
UserProjectAccessChangedService
.
new
([
1
,
2
])
}
before
do
allow
(
Gitlab
::
Database
::
LoadBalancing
).
to
receive
(
:enable?
).
and_return
(
true
)
expect
(
AuthorizedProjectsWorker
).
to
receive
(
:bulk_perform_and_wait
)
.
with
([[
1
],
[
2
]])
.
and_return
(
10
)
end
it
'sticks all the updated users and returns the original result'
,
:aggregate_failures
do
expect
(
Gitlab
::
Database
::
LoadBalancing
::
Sticking
).
to
receive
(
:bulk_stick
).
with
(
:user
,
[
1
,
2
])
expect
(
service
.
execute
).
to
eq
(
10
)
end
it
'avoids N+1 cached queries'
,
:use_sql_query_cache
,
:request_store
do
# Run this once to establish a baseline
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
do
service
.
execute
end
service
=
UserProjectAccessChangedService
.
new
([
1
,
2
,
3
,
4
,
5
])
allow
(
AuthorizedProjectsWorker
).
to
receive
(
:bulk_perform_and_wait
)
.
with
([[
1
],
[
2
],
[
3
],
[
4
],
[
5
]])
.
and_return
(
10
)
expect
{
service
.
execute
}.
not_to
exceed_all_query_limit
(
control_count
.
count
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment