From 7e7f4216ab51c73556516bdc506e5fb4555550cd Mon Sep 17 00:00:00 2001 From: francisco Date: Mon, 2 Dec 2024 12:13:09 -0300 Subject: [PATCH] feat(api): add filters logic in backend Close #619 Part of #600, #447 --- .../kernelCI_app/views/hardwareDetailsView.py | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/backend/kernelCI_app/views/hardwareDetailsView.py b/backend/kernelCI_app/views/hardwareDetailsView.py index c56f0b3a..91f9f23a 100644 --- a/backend/kernelCI_app/views/hardwareDetailsView.py +++ b/backend/kernelCI_app/views/hardwareDetailsView.py @@ -159,16 +159,15 @@ def get_filters(self, filters): } for key, value in filters.items(): - _, filter_item = key.split("_") + key = key.replace("filter_", "") - filter_split = filter_item.split(".") - if len(filter_split) == 2: - table, field = filter_item.split(".") + table = "build" + if "." in key: + table, field = key.split(".") else: - table = "build" - field = filter_item + field = key - if table == "build": + if field == "valid": value = [x == "Success" for x in value] filters_map[table].append({"field": field, "value": value}) @@ -192,6 +191,7 @@ def pass_in_filters(self, data, filters): def sanitize_records(self, records, selected_trees, filters): processed_builds = set() + filtered_builds = set() builds = {"items": [], "issues": {}, "failedWithUnknownIssues": 0} filters_map = self.get_filters(filters) @@ -208,10 +208,24 @@ def sanitize_records(self, records, selected_trees, filters): status = r["status"] table_test = "boot" if is_boot(r) else "test" - test_filter_is_empty = len(filters_map[table_test]) == 0 + test_filter_is_empty = len(filters_map['build']) == 0 and len(filters_map[table_test]) == 0 test_pass_in_filters = self.pass_in_filters(r, filters_map[table_test]) - jump_test = not test_filter_is_empty and not test_pass_in_filters + build_pass_in_filters = True + + if build_id not in processed_builds: + processed_builds.add(build_id) + build = get_build(r, current_tree["index"]) + + if len(filters_map['build']) == 0 or self.pass_in_filters(build, filters_map['build']): + filtered_builds.add(build_id) + builds["items"].append(build) + else: + build_pass_in_filters = False + + update_issues(r, builds, r["build__valid"] is False) + + jump_test = not test_filter_is_empty and (not test_pass_in_filters or not build_pass_in_filters) if not jump_test: tests_or_boots = boots if is_boot(r) else tests @@ -235,15 +249,6 @@ def sanitize_records(self, records, selected_trees, filters): update_issues(r, tests_or_boots, status == STATUS_FAILED_VALUE) - if build_id not in processed_builds: - processed_builds.add(build_id) - build = get_build(r, current_tree["index"]) - - if len(filters_map['build']) == 0 or self.pass_in_filters(build, filters_map['build']): - builds["items"].append(build) - - update_issues(r, builds, r["build__valid"] is False) - builds["summary"] = create_details_build_summary(builds["items"]) properties2List(builds, ["issues"]) properties2List(tests, ["issues", "platformsFailing", "archSummary"])