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
6857e1d0
Commit
6857e1d0
authored
Jun 16, 2020
by
charlieablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid title length overflows
- More terse deletion logic
parent
57adce0c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
9 deletions
+26
-9
db/migrate/20200305082754_remove_duplicate_labels_from_project.rb
...te/20200305082754_remove_duplicate_labels_from_project.rb
+7
-6
doc/user/project/labels.md
doc/user/project/labels.md
+1
-1
spec/migrations/remove_duplicate_labels_from_project_spec.rb
spec/migrations/remove_duplicate_labels_from_project_spec.rb
+18
-2
No files found.
db/migrate/20200305082754_remove_duplicate_labels_from_project.rb
View file @
6857e1d0
...
...
@@ -70,19 +70,20 @@ WITH data AS (
# create backup records
BackupLabel
.
insert_all!
(
duplicate_labels
.
map
{
|
label
|
label
.
except
(
"row_number"
)
})
ApplicationRecord
.
connection
.
execute
(
<<-
SQL
.
squish
)
DELETE FROM labels
WHERE labels.id IN (
#{
duplicate_labels
.
map
{
|
dup
|
dup
[
"id"
]
}
.join(", ")});
SQL
Label
.
where
(
id:
duplicate_labels
.
pluck
(
"id"
)).
delete_all
end
end
def
rename_partial_duplicates
(
start_id
,
stop_id
)
# We need to ensure that the new title (with `_duplicate#{ID}`) doesn't exceed the limit.
# Truncate the original title (if needed) to 245 characters minus the length of the ID
# then add `_duplicate#{ID}`
soft_duplicates
=
ApplicationRecord
.
connection
.
execute
(
<<-
SQL
.
squish
)
WITH data AS (
SELECT
*,
title || '_' || 'duplicate' || id AS
new_title,
substring(title from 1 for 245 - length(id::text)) || '_duplicate' || id::text as
new_title,
#{
RENAME
}
AS restore_action,
row_number() OVER (PARTITION BY project_id, title ORDER BY id) AS row_number
FROM labels
...
...
@@ -95,7 +96,7 @@ WITH data AS (
BackupLabel
.
insert_all!
(
soft_duplicates
.
map
{
|
label
|
label
.
except
(
"row_number"
)
})
ApplicationRecord
.
connection
.
execute
(
<<-
SQL
.
squish
)
UPDATE labels SET title =
title || '_' || 'duplicate' || extract(epoch from now())
UPDATE labels SET title =
substring(title from 1 for 245 - length(id::text)) || '_duplicate' || id::text
WHERE labels.id IN (
#{
soft_duplicates
.
map
{
|
dup
|
dup
[
"id"
]
}
.join(", ")});
SQL
end
...
...
doc/user/project/labels.md
View file @
6857e1d0
...
...
@@ -259,7 +259,7 @@ Ties are broken arbitrarily.
In specific circumstances it was possible to create labels with duplicate titles in the same
namespace.
To resolve the duplication,
[
in GitLab 13.
0
](
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/21384
)
To resolve the duplication,
[
in GitLab 13.
1
](
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/21384
)
and later, some duplicate labels have
`_duplicate<number>`
appended to their titles.
You can safely change these labels' titles if you prefer.
...
...
spec/migrations/remove_duplicate_labels_from_project_spec.rb
View file @
6857e1d0
...
...
@@ -198,8 +198,8 @@ describe RemoveDuplicateLabelsFromProject do
it
'modifies the titles of the partial duplicates'
do
migration
.
up
expect
(
second_label
.
reload
.
title
).
to
match
(
/
#{
label_title
}
_duplicate/
)
expect
(
fourth_label
.
reload
.
title
).
to
match
(
/
#{
other_title
}
_duplicate/
)
expect
(
second_label
.
reload
.
title
).
to
match
(
/
#{
label_title
}
_duplicate
#{
second_label
.
id
}
$
/
)
expect
(
fourth_label
.
reload
.
title
).
to
match
(
/
#{
other_title
}
_duplicate
#{
fourth_label
.
id
}
$
/
)
end
it
'restores renamed records on rollback'
do
...
...
@@ -213,6 +213,22 @@ describe RemoveDuplicateLabelsFromProject do
expect
(
second_label
.
reload
.
attributes
).
to
include
(
second_label_attributes
)
expect
(
fourth_label
.
reload
.
attributes
).
to
include
(
fourth_label_attributes
)
end
context
'when the labels have a long title that might overflow'
do
let
(
:long_title
)
{
"a"
*
255
}
before
do
first_label
.
update_attribute
(
:title
,
long_title
)
second_label
.
update_attribute
(
:title
,
long_title
)
end
it
'keeps the length within the limit'
do
migration
.
up
expect
(
second_label
.
reload
.
title
).
to
eq
(
"
#{
"a"
*
244
}
_duplicate
#{
second_label
.
id
}
"
)
expect
(
second_label
.
title
.
length
).
to
eq
255
end
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