SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
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
cb9b7799
Commit
cb9b7799
authored
5 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
Optimize queryset
parent
fd471c37
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
submissions/managers.py
+20
-20
20 additions, 20 deletions
submissions/managers.py
with
20 additions
and
20 deletions
submissions/managers.py
+
20
−
20
View file @
cb9b7799
...
@@ -15,23 +15,23 @@ now = timezone.now()
...
@@ -15,23 +15,23 @@ now = timezone.now()
class
SubmissionQuerySet
(
models
.
QuerySet
):
class
SubmissionQuerySet
(
models
.
QuerySet
):
def
_newest_version_only
(
self
,
queryset
):
#
def _newest_version_only(self, queryset):
"""
#
"""
TODO: Make more efficient... with agregation or whatever.
#
TODO: Make more efficient... with agregation or whatever.
#
The current Queryset should return only the latest version
#
The current Queryset should return only the latest version
of the Arxiv submissions known to SciPost.
#
of the Arxiv submissions known to SciPost.
#
Method only compatible with PostGresQL
#
Method only compatible with PostGresQL
"""
#
"""
# This method used a double query, which is a consequence of the complex distinct()
#
# This method used a double query, which is a consequence of the complex distinct()
# filter combined with the PostGresQL engine. Without the double query, ordering
#
# filter combined with the PostGresQL engine. Without the double query, ordering
# on a specific field after filtering seems impossible.
#
# on a specific field after filtering seems impossible.
ids
=
(
queryset
#
ids = (queryset
.
order_by
(
'
preprint__identifier_wo_vn_nr
'
,
'
-preprint__vn_nr
'
)
#
.order_by('preprint__identifier_wo_vn_nr', '-preprint__vn_nr')
.
distinct
(
'
preprint__identifier_wo_vn_nr
'
)
#
.distinct('preprint__identifier_wo_vn_nr')
.
values_list
(
'
id
'
,
flat
=
True
))
#
.values_list('id', flat=True))
return
queryset
.
filter
(
id__in
=
ids
)
#
return queryset.filter(id__in=ids)
def
user_filter
(
self
,
user
):
def
user_filter
(
self
,
user
):
"""
Filter on basic conflict of interests.
"""
Filter on basic conflict of interests.
...
@@ -143,7 +143,7 @@ class SubmissionQuerySet(models.QuerySet):
...
@@ -143,7 +143,7 @@ class SubmissionQuerySet(models.QuerySet):
This query contains set of public() submissions, filtered to only the newest available
This query contains set of public() submissions, filtered to only the newest available
version.
version.
"""
"""
return
self
.
_newest_version_only
(
self
.
public
()
)
return
self
.
filter
(
is_resubmission_of__isnull
=
True
)
.
public
()
def
treated
(
self
):
def
treated
(
self
):
"""
This query returns all Submissions that are presumed to be
'
done
'
.
"""
"""
This query returns all Submissions that are presumed to be
'
done
'
.
"""
...
@@ -189,11 +189,11 @@ class SubmissionQuerySet(models.QuerySet):
...
@@ -189,11 +189,11 @@ class SubmissionQuerySet(models.QuerySet):
def
rejected
(
self
):
def
rejected
(
self
):
"""
Return rejected Submissions.
"""
"""
Return rejected Submissions.
"""
return
self
.
_newest_version_only
(
self
.
filter
(
status
=
constants
.
STATUS_REJECTED
)
)
return
self
.
filter
(
is_resubmission_of__isnull
=
True
,
status
=
constants
.
STATUS_REJECTED
)
def
withdrawn
(
self
):
def
withdrawn
(
self
):
"""
Return withdrawn Submissions.
"""
"""
Return withdrawn Submissions.
"""
return
self
.
_newest_version_only
(
self
.
filter
(
status
=
constants
.
STATUS_WITHDRAWN
)
)
return
self
.
filter
(
is_resubmission_of__isnull
=
True
,
status
=
constants
.
STATUS_WITHDRAWN
)
def
open_for_reporting
(
self
):
def
open_for_reporting
(
self
):
"""
Return Submission that allow for reporting.
"""
"""
Return Submission that allow for reporting.
"""
...
...
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