Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
f3fc6987
Commit
f3fc6987
authored
3 years ago
by
Manon Blanco
Browse files
Options
Downloads
Patches
Plain Diff
Use select_related
parent
29d00c73
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/dataimport/migrations/0040_use_worker_configuration.py
+13
-6
13 additions, 6 deletions
...ex/dataimport/migrations/0040_use_worker_configuration.py
with
13 additions
and
6 deletions
arkindex/dataimport/migrations/0040_use_worker_configuration.py
+
13
−
6
View file @
f3fc6987
# Generated by Django 3.2.5 on 2021-11-04 08:14
from
collections
import
defaultdict
from
django.db
import
migrations
from
arkindex.dataimport.utils
import
hash_object
...
...
@@ -9,16 +11,21 @@ def use_worker_configuration(apps, schema_editor):
WorkerRun
=
apps
.
get_model
(
'
dataimport
'
,
'
WorkerRun
'
)
WorkerConfiguration
=
apps
.
get_model
(
'
dataimport
'
,
'
WorkerConfiguration
'
)
for
index
,
worker_run
in
enumerate
(
WorkerRun
.
objects
.
filter
(
configuration__isnull
=
True
).
exclude
(
old_configuration
=
{})):
indexes
=
defaultdict
(
int
)
for
worker_run
in
WorkerRun
.
objects
.
filter
(
configuration__isnull
=
True
)
\
.
exclude
(
old_configuration
=
{})
\
.
select_related
(
'
version__worker
'
):
worker
=
worker_run
.
version
.
worker
worker_configuration
,
_
=
WorkerConfiguration
.
objects
.
get_or_create
(
worker_configuration
,
created
=
WorkerConfiguration
.
objects
.
get_or_create
(
worker
=
worker
,
configuration
=
worker_run
.
old_configuration
,
configuration
_hash
=
hash_object
(
worker_run
.
old_configuration
)
,
defaults
=
{
'
name
'
:
f
'
config n°
{
index
}
-
{
worker
.
name
}
'
,
'
configuration
_hash
'
:
hash_object
(
worker_run
.
old_configuration
)
'
name
'
:
f
'
config
for
{
worker
.
name
}
n°
{
index
es
[
worker
.
id
]
+
1
}
'
,
'
configuration
'
:
worker_run
.
old_configuration
}
)
indexes
[
worker
.
id
]
+=
created
worker_run
.
configuration
=
worker_configuration
worker_run
.
save
()
...
...
@@ -26,7 +33,7 @@ def use_worker_configuration(apps, schema_editor):
def
use_old_configuration
(
apps
,
schema_editor
):
WorkerRun
=
apps
.
get_model
(
'
dataimport
'
,
'
WorkerRun
'
)
worker_runs
=
WorkerRun
.
objects
.
filter
(
configuration__isnull
=
False
)
worker_runs
=
WorkerRun
.
objects
.
filter
(
configuration__isnull
=
False
)
.
select_related
(
'
configuration
'
)
for
worker_run
in
worker_runs
:
worker_run
.
old_configuration
=
worker_run
.
configuration
.
configuration
WorkerRun
.
objects
.
bulk_update
(
worker_runs
,
[
'
old_configuration
'
])
...
...
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