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
65d0b8be
Commit
65d0b8be
authored
Sep 30, 2020
by
Alex Kalderimis
Committed by
Alex Kalderimis
Oct 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow set_all to do the grouping
parent
1567fd8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
15 deletions
+9
-15
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+7
-13
lib/gitlab/database/set_all.rb
lib/gitlab/database/set_all.rb
+2
-2
No files found.
app/models/concerns/relative_positioning.rb
View file @
65d0b8be
...
...
@@ -102,22 +102,16 @@ module RelativePositioning
delta
=
at_end
?
gap
:
-
gap
indexed
=
(
at_end
?
objects
:
objects
.
reverse
).
each_with_index
# Some classes are polymorphic, and not all siblings are in the same table.
by_model
=
indexed
.
group_by
{
|
pair
|
pair
.
first
.
model_class
}
lower_bound
,
upper_bound
=
at_end
?
[
position
,
MAX_POSITION
]
:
[
MIN_POSITION
,
position
]
by_model
.
each
do
|
model
,
pairs
|
model
.
transaction
do
pairs
.
each_slice
(
100
)
do
|
batch
|
mapping
=
batch
.
to_h
.
transform_values!
do
|
i
|
desired_pos
=
position
+
delta
*
(
i
+
1
)
{
relative_position:
desired_pos
.
clamp
(
lower_bound
,
upper_bound
)
}
end
::
Gitlab
::
Database
::
SetAll
::
Setter
.
new
(
model
,
[
:relative_position
],
mapping
)
.
update!
representative
.
model_class
.
transaction
do
indexed
.
each_slice
(
100
)
do
|
batch
|
mapping
=
batch
.
to_h
.
transform_values!
do
|
i
|
desired_pos
=
position
+
delta
*
(
i
+
1
)
{
relative_position:
desired_pos
.
clamp
(
lower_bound
,
upper_bound
)
}
end
::
Gitlab
::
Database
::
SetAll
.
set_all
([
:relative_position
],
mapping
,
&
:model_class
)
end
end
...
...
lib/gitlab/database/set_all.rb
View file @
65d0b8be
...
...
@@ -103,8 +103,8 @@ module Gitlab
end
end
def
self
.
set_all
(
columns
,
mapping
)
mapping
.
group_by
{
|
k
,
v
|
k
.
class
}.
each
do
|
model
,
entries
|
def
self
.
set_all
(
columns
,
mapping
,
&
to_class
)
mapping
.
group_by
{
|
k
,
v
|
block_given?
?
to_class
.
call
(
k
)
:
k
.
class
}.
each
do
|
model
,
entries
|
Setter
.
new
(
model
,
columns
,
entries
).
update!
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