Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #381 from Bidaya0/Enhancement/issue-380
Browse files Browse the repository at this point in the history
Enhancement: optimise agent_id query logic
  • Loading branch information
Bidaya0 committed Jan 7, 2022
2 parents 6cdab60 + 600b5e7 commit a41614b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
18 changes: 9 additions & 9 deletions iast/base/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def get_agents_with_project(project_name, users):
"""
agent_ids = []
if project_name and project_name != '':
project_queryset = IastProject.objects.filter(user__in=users, name__icontains=project_name).values("id")
project_ids = []
project_ids = IastProject.objects.filter(
user__in=users,
name__icontains=project_name).values_list("id", flat=True).all()

if project_queryset:
for pro_item in project_queryset:
project_ids.append(pro_item['id'])
if project_ids:

relations = IastAgent.objects.filter(bind_project_id__in=project_ids).values("id")
agent_ids = [relation['id'] for relation in relations]
agent_ids = IastAgent.objects.filter(
bind_project_id__in=project_ids).values_list("id",
flat=True).all()

return agent_ids

Expand Down Expand Up @@ -143,9 +143,9 @@ def get_vul_count_by_agent(agent_ids, vid, user):
typeArr = {}
typeLevel = {}
for one in typeInfo:
hook_type = hooktypes.get('hook_type_id', None)
hook_type = hooktypes.get(one['hook_type_id'], None)
hook_type_name = hook_type['name'] if hook_type else None
strategy = strategys.get('strategy_id', None)
strategy = strategys.get(one['strategy_id'], None)
strategy_name = strategy['vul_name'] if strategy else None
type_ = list(
filter(lambda x: x is not None, [strategy_name, hook_type_name]))
Expand Down
15 changes: 9 additions & 6 deletions iast/views/project_report_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@

class _ProjectReportExportQuerySerializer(serializers.Serializer):
vid = serializers.CharField(
help_text=_("The version id of the project"))
help_text=_("The version id of the project"),
required=False)
pname = serializers.CharField(
help_text=_("The name of the project"))
pid = serializers.IntegerField(help_text=_("The id of the project"))
help_text=_("The name of the project"),
required=False)
pid = serializers.IntegerField(help_text=_("The id of the project"),
required=False)

class ProjectReportExport(UserEndPoint):
name = 'api-v1-word-maker'
Expand All @@ -46,9 +49,9 @@ def get_agents_with_project_id(pid, auth_users):
:param auth_users:
:return:
"""
relations = IastAgent.objects.filter(bind_project_id=pid,
user__in=auth_users).values("id")
agent_ids = [relation['id'] for relation in relations]
agent_ids = IastAgent.objects.filter(bind_project_id=pid,
user__in=auth_users).values_list(
"id", flat=True).all()
return agent_ids

@staticmethod
Expand Down

0 comments on commit a41614b

Please sign in to comment.