Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
0ad2413b
Unverified
Commit
0ad2413b
authored
1 year ago
by
Eugen Rochko
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix n+1 query in settings migration (#24783)
parent
f1c1fa14
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
db/migrate/20230215074423_move_user_settings.rb
+16
-13
16 additions, 13 deletions
db/migrate/20230215074423_move_user_settings.rb
with
16 additions
and
13 deletions
db/migrate/20230215074423_move_user_settings.rb
+
16
−
13
View file @
0ad2413b
...
...
@@ -59,26 +59,29 @@ class MoveUserSettings < ActiveRecord::Migration[6.1]
end
def
up
User
.
find_
each
do
|
user
|
previous_settings
=
LegacySetting
.
where
(
thing_type:
'User'
,
thing_id:
user
.
id
).
index
_by
(
&
:
var
)
User
.
find_
in_batches
do
|
user
s
|
previous_settings
_for_batch
=
LegacySetting
.
where
(
thing_type:
'User'
,
thing_id:
user
s
.
map
(
&
:
id
)
)
.
group
_by
(
&
:
thing_id
)
user_settings
=
{}
users
.
each
do
|
user
|
previous_settings
=
previous_settings_for_batch
[
user
.
id
]
&
.
index_by
(
&
:var
)
||
{}
user_settings
=
{}
MAPPING
.
each
do
|
legacy_key
,
new_key
|
value
=
previous_settings
[
legacy_key
]
&
.
value
MAPPING
.
each
do
|
legacy_key
,
new_key
|
value
=
previous_settings
[
legacy_key
]
&
.
value
next
if
value
.
blank?
next
if
value
.
blank?
if
value
.
is_a?
(
Hash
)
value
.
each
do
|
nested_key
,
nested_value
|
user_settings
[
MAPPING
[
legacy_key
][
nested_key
.
to_sym
]]
=
nested_value
if
value
.
is_a?
(
Hash
)
value
.
each
do
|
nested_key
,
nested_value
|
user_settings
[
MAPPING
[
legacy_key
][
nested_key
.
to_sym
]]
=
nested_value
end
else
user_settings
[
new_key
]
=
value
end
else
user_settings
[
new_key
]
=
value
end
end
user
.
update_column
(
'settings'
,
Oj
.
dump
(
user_settings
))
# rubocop:disable Rails/SkipsModelValidations
user
.
update_column
(
'settings'
,
Oj
.
dump
(
user_settings
))
# rubocop:disable Rails/SkipsModelValidations
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment