in backend/code_review_backend/issues/api.py [0:0]
def get_queryset(self):
queryset = (
Issue.objects.values(
"issue_links__revision__head_repository__slug",
"analyzer",
"analyzer_check",
)
# We want to count distinct issues because they can be referenced on multiple diffs
.annotate(total=Count("id", distinct=True))
.annotate(
has_check=ExpressionWrapper(
Q(analyzer_check__isnull=True), output_field=BooleanField()
)
)
.annotate(
publishable=Count(
"id", filter=Q(issue_links__in_patch=True) | Q(level=LEVEL_ERROR)
)
)
.distinct(
"issue_links__revision__head_repository__slug",
"analyzer",
"analyzer_check",
)
)
# Filter issues by date
since = self.request.query_params.get("since")
if since is not None:
try:
since = datetime.strptime(since, "%Y-%m-%d").date()
except ValueError:
raise APIException(detail="invalid since date - should be YYYY-MM-DD")
else:
# Because of the perf. hit filter, issues that are not older than today - 3 months.
since = date.today() - timedelta(days=90)
queryset = queryset.filter(issue_links__revision__created__gte=since).distinct()
return queryset.order_by(
"-total",
"issue_links__revision__head_repository__slug",
"analyzer",
# Use same order than PostgreSQL with SQLite
"has_check",
"analyzer_check",
).values(
"issue_links__revision__head_repository__slug",
"analyzer",
"analyzer_check",
"total",
"publishable",
"issue_links__in_patch",
"issue_links__new_for_revision",
)