Skip to content

Commit

Permalink
feat(api): add filters logic in backend
Browse files Browse the repository at this point in the history
Close #619
Part of #600, #447
  • Loading branch information
Francisco2002 committed Dec 2, 2024
1 parent da9e671 commit 7e7f421
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions backend/kernelCI_app/views/hardwareDetailsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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"])
Expand Down

0 comments on commit 7e7f421

Please sign in to comment.