-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimization: 任务历史搜索优化 (closed #1856) #1915
optimization: 任务历史搜索优化 (closed #1856) #1915
Conversation
2cf65a2
to
52d9351
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## v2.4.4-dev #1915 +/- ##
==============================================
+ Coverage 74.96% 74.99% +0.02%
==============================================
Files 403 403
Lines 27856 27890 +34
==============================================
+ Hits 20883 20916 +33
- Misses 6973 6974 +1 ☔ View full report in Codecov by Sentry. |
apps/node_man/serializers/meta.py
Outdated
|
||
class FilterConditionSerializer(serializers.Serializer): | ||
category = serializers.CharField(label=_("分类"), required=False, default="") | ||
bk_biz_ids = serializers.ListField(label=_("业务列表"), required=False, default=[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指定 child
@@ -58,11 +62,13 @@ def fetch_cloud_unique_col_count(self, col): | |||
""" | |||
return Cloud.objects.values_list(col, flat=True).distinct().count() | |||
|
|||
def fetch_Job_unique_col_count(self): | |||
def fetch_Job_unique_col_count(self, search_business=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
命名规范:Job
-> job
apps/node_man/tools/job.py
Outdated
def get_job_queryset_with_biz_scope(cls, all_biz_info, biz_info, biz_permission, search_biz_ids, kwargs): | ||
""" | ||
根据用户所拥有的业务权限进行Job的筛选 | ||
:param all_biz_info: 所有的业务id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里似乎也是 dict?
apps/node_man/tools/job.py
Outdated
# 业务权限 | ||
if search_biz_ids: | ||
# 字典的 in 比列表性能更高 | ||
biz_scope = [bk_biz_id for bk_biz_id in search_biz_ids if bk_biz_id in biz_info] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
等价操作:set(biz_permission) & set(search_biz_id)
apps/node_man/tools/job.py
Outdated
biz_scope_query_q = Q() | ||
elif need_reverse_query: | ||
biz_scope_query_q = reduce( | ||
operator.and_, [Q(bk_biz_scope__contains=bk_biz_id) for bk_biz_id in biz_scope], Q() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not A and not B and not C
= not (A or B or C)
"start_time": "2023-10-01 12:00:00", | ||
"end_time": "2023-10-03 12:00:00", | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
似乎没有配置 pre-commit
?
self.assertEqual(result, [ | ||
{"name": _("任务ID"), "id": "job_id"}, | ||
{"name": _("IP"), "id": "inner_ip_list"}, | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以再补充一个单元测试,验证取反的场景
5e7cf8c
to
626e387
Compare
apps/node_man/tools/job.py
Outdated
""" | ||
# 业务权限 | ||
if search_biz_ids: | ||
# 字典的 in 比列表性能更高 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释似乎和代码没啥关系
72bf7a8
to
db90d74
Compare
@@ -73,13 +79,28 @@ def fetch_Job_unique_col_count(self): | |||
|
|||
for job in job_condition: | |||
# 判断权限 | |||
if set(job["bk_biz_scope"]) - {biz["bk_biz_id"] for biz in SEARCH_BUSINESS} == set(): | |||
if any(biz_id in {biz["bk_biz_id"] for biz in search_business} for biz_id in set(job["bk_biz_scope"])): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
虽然是测试代码,但最好把一些公共变量放到 for 循环外面,避免占用内存
set(job["bk_biz_scope"])
{biz["bk_biz_id"] for biz in search_business}
db90d74
to
16f1d03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR
CheckList(PR Assigners)
确认已完成以下操作:
backlog
->todo
->for test
->tested(需通过测试同学测试)
->done
pr/reviewable
CheckList(PR Reviewers)
确认已完成以下操作:
pr/reviewable
,要求重新修改