SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
119
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
SciPost
SciPost
Commits
52671ada
Commit
52671ada
authored
2 weeks ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
perf:
️ use prefetch in author affil indices list
parent
f09af5e6
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
scipost_django/journals/models/publication.py
+13
-2
13 additions, 2 deletions
scipost_django/journals/models/publication.py
with
13 additions
and
2 deletions
scipost_django/journals/models/publication.py
+
13
−
2
View file @
52671ada
...
...
@@ -34,6 +34,7 @@ from scipost.fields import ChoiceArrayField
if
TYPE_CHECKING
:
from
django.db.models.manager
import
RelatedManager
from
production.models
import
ProofsRepository
from
profiles.models
import
Profile
...
...
@@ -208,6 +209,9 @@ class Publication(models.Model):
objects
=
PublicationQuerySet
.
as_manager
()
if
TYPE_CHECKING
:
authors
=
RelatedManager
[
PublicationAuthorsTable
]
class
Meta
:
default_related_name
=
"
publications
"
ordering
=
(
"
-publication_date
"
,
"
-paper_nr
"
)
...
...
@@ -302,21 +306,28 @@ class Publication(models.Model):
return
self
.
cf_author_affiliation_indices_list
indexed_author_list
=
[]
for
author
in
self
.
authors
.
all
():
pub_affiliations
=
self
.
get_all_affiliations
()
pub_authors
=
self
.
authors
.
all
().
prefetch_related
(
"
affiliations
"
)
for
author
in
pub_authors
:
affnrs
=
[]
for
idx
,
aff
in
enumerate
(
self
.
get_all
_affiliations
()
):
for
idx
,
aff
in
enumerate
(
pub
_affiliations
):
if
aff
in
author
.
affiliations
.
all
():
affnrs
.
append
(
idx
+
1
)
# If no affiliation is found, add a None to the list
# Prevents crashes since Django v4
if
len
(
affnrs
)
==
0
:
affnrs
=
[
None
]
indexed_author_list
.
append
(
affnrs
)
# Since nested ArrayFields must have the same dimension,
# we pad the "empty" entries with Null:
max_length
=
0
for
entry
in
indexed_author_list
:
max_length
=
max
(
max_length
,
len
(
entry
))
padded_list
=
[]
for
entry
in
indexed_author_list
:
padded_entry
=
entry
+
[
None
]
*
(
max_length
-
len
(
entry
))
...
...
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