diff --git a/docs/source/modules/tcms.core.helpers.cache.rst b/docs/source/modules/tcms.core.helpers.cache.rst deleted file mode 100644 index a1a5f707e1..0000000000 --- a/docs/source/modules/tcms.core.helpers.cache.rst +++ /dev/null @@ -1,7 +0,0 @@ -tcms\.core\.helpers\.cache module -================================= - -.. automodule:: tcms.core.helpers.cache - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/modules/tcms.core.helpers.rst b/docs/source/modules/tcms.core.helpers.rst index 5687061d90..309490fa6c 100644 --- a/docs/source/modules/tcms.core.helpers.rst +++ b/docs/source/modules/tcms.core.helpers.rst @@ -11,6 +11,5 @@ Submodules .. toctree:: - tcms.core.helpers.cache tcms.core.helpers.comments diff --git a/tcms/core/helpers/cache.py b/tcms/core/helpers/cache.py deleted file mode 100644 index b5053d3697..0000000000 --- a/tcms/core/helpers/cache.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -from django.contrib.contenttypes.models import ContentType -from django.core.cache import cache - - -def cached_entities(content_type_name): - """ - Some entities are frequently used.\n - Cache them for reuse.\n - Retrieve using model names. - """ - content_type_key = 'ctt_type_' + content_type_name - content_type = cache.get(content_type_key) - if not content_type: - content_type = ContentType.objects.get(model__iexact=content_type_name) - cache.set(content_type_key, content_type) - model_class = content_type.model_class() - key = 'cached_' + content_type_name - entities = cache.get(key) - if not entities: - entities = model_class.objects.all() - cache.set(key, entities) - return entities diff --git a/tcms/search/__init__.py b/tcms/search/__init__.py index 3af0975a0e..5d66fc9605 100644 --- a/tcms/search/__init__.py +++ b/tcms/search/__init__.py @@ -11,14 +11,13 @@ from django.shortcuts import render from django.views.decorators.http import require_GET -from tcms.core.helpers.cache import cached_entities from tcms.core.utils.raw_sql import RawSQL -from tcms.management.models import Priority +from tcms.management.models import Priority, Product from tcms.search.forms import CaseForm, RunForm, PlanForm from tcms.search.order import order_targets from tcms.search.query import SmartDjangoQuery from tcms.testcases.models import TestCase -from tcms.testplans.models import TestPlan +from tcms.testplans.models import TestPlan, PlanType from tcms.testruns.models import TestRun @@ -43,9 +42,9 @@ def advance_search(request): if errors or not data: product_choice = [] - for product in cached_entities('product'): + for product in Product.objects.all(): product_choice.append((product.pk, product.name)) - plan_type_choices = cached_entities('plantype') # pylint: disable=unused-variable + plan_type_choices = PlanType.objects.all() # pylint: disable=unused-variable errors = _fmt_errors(errors) priorities = Priority.objects.filter( # pylint: disable=unused-variable is_active=True).order_by('value') diff --git a/tcms/search/forms.py b/tcms/search/forms.py index 131562da9d..7209b305f4 100644 --- a/tcms/search/forms.py +++ b/tcms/search/forms.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- from django import forms -from tcms.core.helpers.cache import cached_entities -from tcms.management.models import Product, Build, Component, Version +from tcms.management.models import Product, Priority, Build, Component, Version from tcms.testcases.forms import BugField -from tcms.testcases.models import Category +from tcms.testcases.models import Category, TestCaseStatus from tcms.testplans.models import PlanType @@ -141,12 +140,12 @@ def clean_cs_tester(self): def populate(self, data): status_choices = [] - for test_case_status in cached_entities('TestCaseStatus'): + for test_case_status in TestCaseStatus.objects.all(): status_choices.append((test_case_status.pk, test_case_status.name)) self.fields['cs_status'].choices = status_choices priority_choices = [] - for priority in cached_entities('Priority'): + for priority in Priority.objects.all(): priority_choices.append((priority.pk, priority.value)) self.fields['cs_priority'].choices = priority_choices