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

Enhancement: optimise agent_id query logic #381

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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