Skip to content

Commit

Permalink
Combine id_list and tenant_components in filter function; Immediately…
Browse files Browse the repository at this point in the history
… return empty list if id_list&tenant_components is empty
  • Loading branch information
mharding-hpe committed Dec 17, 2024
1 parent 579c598 commit 7d5a911
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/bos/server/controllers/v2/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,28 @@ def get_v2_components_data(id_list=None,
Allows filtering using a comma separated list of ids.
"""
if any([id_list, enabled, session, staged_session, phase, status, tenant]):
tenant_components = None if not tenant else get_tenant_component_set(
tenant)
tenant_components = None if tenant is None else get_tenant_component_set(tenant)

if id_list is not None:
id_set = set(id_list)
if tenant_components is not None:
id_set.intersection_update(tenant_components)
else:
id_set = tenant_components

# If id_set is not None but is empty, that means no components in the system
# will match our filter, so we can return an empty list immediately.
if id_set is not None and not id_set:
return []

if any([id_set, enabled, session, staged_session, phase, status]):
_component_filter_func = partial(_filter_component,
id_list=id_list or None,
id_set=id_set,
enabled=enabled,
session=session or None,
staged_session=staged_session or None,
phase=phase or None,
status=status or None,
tenant_components=tenant_components
or None)
status=status or None)
elif delete_timestamp:
_component_filter_func = partial(_set_status,
delete_timestamp=delete_timestamp)
Expand All @@ -124,16 +134,15 @@ def get_v2_components_data(id_list=None,


def _filter_component(data: dict,
id_list=None,
id_set=None,
enabled=None,
session=None,
staged_session=None,
phase=None,
status=None,
tenant_components=None,
delete_timestamp: bool = False) -> dict | None:
# Do all of the checks we can before calculating status, to avoid doing it needlessly
if id_list is not None and data["id"] not in id_list:
if id_set is not None and data["id"] not in id_set:
return None
if tenant_components is not None and data["id"] not in tenant_components:
return None
Expand Down

0 comments on commit 7d5a911

Please sign in to comment.