Skip to content

Commit

Permalink
Remove RawSQL queries. Fixes #36
Browse files Browse the repository at this point in the history
case_runs_count_by_status_under_run & custom_details_case_run_count
were never used in the code.

the rest of the queries are used in Overall Report and are rewriten
to use a sub-query and annotated counts.
  • Loading branch information
atodorov committed Jul 2, 2018
1 parent 51b7820 commit 9696f25
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 49 deletions.
7 changes: 0 additions & 7 deletions docs/source/modules/tcms.core.utils.raw_sql.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/source/modules/tcms.core.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ Submodules

tcms.core.utils.checksum
tcms.core.utils.mailto
tcms.core.utils.raw_sql
tcms.core.utils.validations

32 changes: 0 additions & 32 deletions tcms/core/utils/raw_sql.py

This file was deleted.

16 changes: 7 additions & 9 deletions tcms/report/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.core.exceptions import ObjectDoesNotExist
from django.urls import reverse
from django.db.models import Count
from django.db.models import Count, OuterRef, Subquery
from django.http import Http404
from django.shortcuts import render
from django.views.generic import TemplateView
Expand All @@ -12,7 +12,6 @@
from tcms.management.models import Priority
from tcms.management.models import Product
from tcms.testruns.models import TestRun, TestCaseRunStatus, TestCaseRun
from tcms.core.utils.raw_sql import RawSQL
from tcms.report.forms import TestingReportForm
from tcms.report.forms import TestingReportCaseRunsListForm
from tcms.report.data import CustomDetailsReportData
Expand All @@ -33,13 +32,12 @@

def overall(request, template_name='report/list.html'):
"""Overall of products report"""
products = Product.objects.all()

products = products.extra(select={
'plans_count': RawSQL.index_product_plans_count,
'runs_count': RawSQL.index_product_runs_count,
'cases_count': RawSQL.index_product_cases_count,
})
cases_count_query = Product.objects.filter(pk=OuterRef('pk')) \
.annotate(cases_num=Count('plan__case')) \
.values('cases_num')
products = Product.objects.annotate(plans_count=Count('plan', distinct=True),
runs_count=Count('plan__run', distinct=True),
cases_count=Subquery(cases_count_query))

context_data = {
'products': products
Expand Down

0 comments on commit 9696f25

Please sign in to comment.