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
ef98985c
Commit
ef98985c
authored
Feb 04, 2021
by
Alexandru Croitor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some code cleanup based on review suggestions
parent
37cdb0f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
18 deletions
+17
-18
app/services/issue_rebalancing_service.rb
app/services/issue_rebalancing_service.rb
+16
-17
config/feature_flags/development/issue_rebalancing_optimization.yml
...ture_flags/development/issue_rebalancing_optimization.yml
+1
-1
No files found.
app/services/issue_rebalancing_service.rb
View file @
ef98985c
...
...
@@ -19,11 +19,18 @@ class IssueRebalancingService
if
Feature
.
enabled?
(
:issue_rebalancing_optimization
)
Issue
.
transaction
do
sort_pairs_by_id
(
start
).
each_slice
(
100
)
{
|
pairs
|
assign_positions_without_position_calculation
(
pairs
)
}
assign_positions
(
start
,
indexed_ids
)
.
sort_by
(
&
:first
)
.
each_slice
(
100
)
do
|
pairs_with_position
|
update_positions
(
pairs_with_position
,
'rebalance issue positions in batches ordered by id'
)
end
end
else
Issue
.
transaction
do
indexed_ids
.
each_slice
(
100
)
{
|
pairs
|
assign_positions
(
start
,
pairs
)
}
indexed_ids
.
each_slice
(
100
)
do
|
pairs
|
pairs_with_position
=
assign_positions
(
start
,
pairs
)
update_positions
(
pairs_with_position
,
'rebalance issue positions'
)
end
end
end
end
...
...
@@ -38,30 +45,22 @@ class IssueRebalancingService
end
# rubocop: enable CodeReuse/ActiveRecord
def
sort_pairs_by_id
(
start
)
indexed_id
s
.
map
do
|
id
,
index
|
def
assign_positions
(
start
,
pairs
)
pair
s
.
map
do
|
id
,
index
|
[
id
,
start
+
(
index
*
gap_size
)]
end
.
sort_by
(
&
:first
)
end
end
def
assign_positions_without_position_calculation
(
pairs_with_position
)
def
update_positions
(
pairs_with_position
,
query_name
)
values
=
pairs_with_position
.
map
do
|
id
,
index
|
"(
#{
id
}
,
#{
index
}
)"
end
.
join
(
', '
)
run_update_query
(
values
)
end
def
assign_positions
(
start
,
positions
)
values
=
positions
.
map
do
|
id
,
index
|
"(
#{
id
}
,
#{
start
+
(
index
*
gap_size
)
}
)"
end
.
join
(
', '
)
run_update_query
(
values
)
run_update_query
(
values
,
query_name
)
end
def
run_update_query
(
values
)
Issue
.
connection
.
exec_query
(
<<~
SQL
,
"rebalance issue positions batches ordered by id"
)
def
run_update_query
(
values
,
query_name
)
Issue
.
connection
.
exec_query
(
<<~
SQL
,
query_name
)
WITH cte(cte_id, new_pos) AS (
SELECT *
FROM (VALUES
#{
values
}
) as t (id, pos)
...
...
config/feature_flags/development/issue_rebalancing_optimization.yml
View file @
ef98985c
---
name
:
issue_rebalancing_optimization
introduced_by_url
:
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53384
rollout_issue_url
:
milestone
:
'
13.9'
type
:
development
...
...
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