Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uhepp.org
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
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frank Sauerburger
uhepp.org
Commits
42444fbf
Verified
Commit
42444fbf
authored
4 years ago
by
Frank Sauerburger
Browse files
Options
Downloads
Patches
Plain Diff
Use custom manager for Plot to defer uhepp loading
parent
71e3f956
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!16
Resolve "Defer uhepp data retrieval"
Pipeline
#7320
failed
4 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
uhepp_org/uhepp_vault/management/commands/fill_plot_title.py
+13
-0
13 additions, 0 deletions
uhepp_org/uhepp_vault/management/commands/fill_plot_title.py
uhepp_org/uhepp_vault/models.py
+14
-0
14 additions, 0 deletions
uhepp_org/uhepp_vault/models.py
with
27 additions
and
0 deletions
uhepp_org/uhepp_vault/management/commands/fill_plot_title.py
0 → 100644
+
13
−
0
View file @
42444fbf
from
django.core.management.base
import
BaseCommand
from
uhepp_vault.models
import
Plot
class
Command
(
BaseCommand
):
def
handle
(
self
,
*
args
,
**
options
):
print
(
"
Setting title fields
"
)
for
plot
in
Plot
.
objects
.
filter
(
title__isnull
=
True
):
print
(
f
"
Update
{
plot
.
uuid
}
"
)
plot
.
title
=
str
(
plot
)
plot
.
save
()
print
(
"
Done
"
)
This diff is collapsed.
Click to expand it.
uhepp_org/uhepp_vault/models.py
+
14
−
0
View file @
42444fbf
...
@@ -40,12 +40,21 @@ class Collection(models.Model):
...
@@ -40,12 +40,21 @@ class Collection(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"
{
self
.
owner
}
:
{
self
.
title
}
"
return
f
"
{
self
.
owner
}
:
{
self
.
title
}
"
class
LazyPlotManger
(
models
.
Manager
):
use_for_related_fields
=
True
def
get_queryset
(
self
,
*
args
,
**
kwargs
):
return
super
()
\
.
get_queryset
(
*
args
,
**
kwargs
)
\
.
defer
(
"
uhepp
"
)
class
Plot
(
models
.
Model
):
class
Plot
(
models
.
Model
):
"""
Database record of a uhepp compliant plot
"""
"""
Database record of a uhepp compliant plot
"""
uuid
=
models
.
UUIDField
(
primary_key
=
True
,
default
=
uuid
.
uuid4
)
uuid
=
models
.
UUIDField
(
primary_key
=
True
,
default
=
uuid
.
uuid4
)
uhepp
=
models
.
JSONField
()
uhepp
=
models
.
JSONField
()
ui_view_count
=
models
.
IntegerField
(
default
=
0
)
ui_view_count
=
models
.
IntegerField
(
default
=
0
)
api_view_count
=
models
.
IntegerField
(
default
=
0
)
api_view_count
=
models
.
IntegerField
(
default
=
0
)
title
=
models
.
TextField
(
null
=
True
,
blank
=
True
)
collection
=
models
.
ForeignKey
(
collection
=
models
.
ForeignKey
(
Collection
,
Collection
,
...
@@ -53,6 +62,8 @@ class Plot(models.Model):
...
@@ -53,6 +62,8 @@ class Plot(models.Model):
related_name
=
'
plots
'
related_name
=
'
plots
'
)
)
objects
=
LazyPlotManger
()
def
view_count
(
self
):
def
view_count
(
self
):
# Plus 1 since increments are not updated
# Plus 1 since increments are not updated
return
self
.
api_view_count
+
self
.
ui_view_count
+
1
return
self
.
api_view_count
+
self
.
ui_view_count
+
1
...
@@ -70,6 +81,9 @@ class Plot(models.Model):
...
@@ -70,6 +81,9 @@ class Plot(models.Model):
)
)
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
title
:
return
self
.
title
try
:
try
:
metadata
=
self
.
uhepp
.
get
(
"
metadata
"
,
{})
metadata
=
self
.
uhepp
.
get
(
"
metadata
"
,
{})
filename
=
metadata
.
get
(
"
filename
"
)
filename
=
metadata
.
get
(
"
filename
"
)
...
...
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