SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit cb9b7799 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Optimize queryset

parent fd471c37
No related branches found
No related tags found
No related merge requests found
...@@ -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."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment