perf(project): 优化命名的风格 (#5693)

perf: 修改错误的地

perf: 优化写错的几个

Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
fit2bot
2021-03-08 10:08:51 +08:00
committed by GitHub
parent 935947c97a
commit 0aa2c2016f
40 changed files with 272 additions and 273 deletions

View File

@@ -13,7 +13,7 @@ from rest_framework.viewsets import GenericViewSet
from common.permissions import IsValidUser
from .http import HttpResponseTemporaryRedirect
from .const import KEY_CACHE_RESOURCES_ID
from .const import KEY_CACHE_RESOURCE_IDS
from .utils import get_logger
from .mixins import CommonApiMixin
@@ -93,7 +93,7 @@ class ResourcesIDCacheApi(APIView):
spm = str(uuid.uuid4())
resources = request.data.get('resources')
if resources is not None:
cache_key = KEY_CACHE_RESOURCES_ID.format(spm)
cache_key = KEY_CACHE_RESOURCE_IDS.format(spm)
cache.set(cache_key, resources, 300)
return Response({'spm': spm})

View File

@@ -7,7 +7,7 @@ create_success_msg = _("%(name)s was created successfully")
update_success_msg = _("%(name)s was updated successfully")
FILE_END_GUARD = ">>> Content End <<<"
celery_task_pre_key = "CELERY_"
KEY_CACHE_RESOURCES_ID = "RESOURCES_ID_{}"
KEY_CACHE_RESOURCE_IDS = "RESOURCE_IDS_{}"
# AD User AccountDisable
# https://blog.csdn.net/bytxl/article/details/17763975

View File

@@ -108,11 +108,11 @@ class IDSpmFilter(filters.BaseFilterBackend):
spm = request.query_params.get('spm')
if not spm:
return queryset
cache_key = const.KEY_CACHE_RESOURCES_ID.format(spm)
resources_id = cache.get(cache_key)
if resources_id is None or not isinstance(resources_id, list):
cache_key = const.KEY_CACHE_RESOURCE_IDS.format(spm)
resource_ids = cache.get(cache_key)
if resource_ids is None or not isinstance(resource_ids, list):
return queryset
queryset = queryset.filter(id__in=resources_id)
queryset = queryset.filter(id__in=resource_ids)
return queryset