Skip to content

Commit

Permalink
feat: search method pool cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidaya0 committed May 19, 2023
1 parent f1a01e5 commit c9ebf4f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions dongtai_common/common/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def get_cache_or_call(*args, **kwargs):
return get_cache_or_call


def disable_cache(function, args=(), kwargs={}):
cache_key = make_hash(
(function.__module__ + function.__name__, args, kwargs))
cache.delete(cache_key)

def cached_decorator(random_range, use_celery_update=False):

def _noname(function):
Expand Down
1 change: 0 additions & 1 deletion dongtai_common/models/vulnerablity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from dongtai_common.models.project import IastProject
from dongtai_common.models.project_version import IastProjectVersion


class IastVulnerabilityStatus(models.Model):
name = models.CharField(max_length=100, blank=True, default='')

Expand Down
3 changes: 3 additions & 0 deletions dongtai_web/views/project_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import ipaddress
import requests
from dongtai_common.models.server import IastServer
from dongtai_common.common.utils import disable_cache
from dongtai_engine.common.queryset import get_scan_id

logger = logging.getLogger("django")

Expand Down Expand Up @@ -184,6 +186,7 @@ def post(self, request):
'base_url', 'test_req_header_key', 'test_req_header_value',
'template_id', 'department_id', 'enable_log', 'log_level'
])
disable_cache(get_scan_id, (project.id))
return R.success(msg='操作成功')
except Exception as e:
logger.error(e, exc_info=e)
Expand Down
8 changes: 6 additions & 2 deletions dongtai_web/views/scan_strategys.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
BatchStatusUpdateSerializerView,
AllStatusUpdateSerializerView,
)
from dongtai_common.common.utils import disable_cache
from dongtai_engine.common.queryset import load_sink_strategy


logger = logging.getLogger('dongtai-webapi')

Expand Down Expand Up @@ -176,8 +179,9 @@ def update(self, request, pk):
if ser.validated_data.get('content', None):
ser.validated_data['content'] = ','.join(
[str(i) for i in ser.validated_data['content']])
obj = IastStrategyUser.objects.filter(
pk=pk).update(**ser.validated_data)
obj = IastStrategyUser.objects.filter(pk=pk).update(
**ser.validated_data)
disable_cache(load_sink_strategy, (), kwargs={"scan_id": pk})
return R.success(msg=_('update success'))

@extend_schema_with_envcheck(
Expand Down

0 comments on commit c9ebf4f

Please sign in to comment.