Skip to content

Commit

Permalink
fix: No array-of-array return in ApiComponentStatus
Browse files Browse the repository at this point in the history
This commit modifies the `ApiComponentStatus` class in `routes.py` to return the cached component if it exists, instead of wrapping it in a list. This improves the efficiency of the API by avoiding unnecessary list creation.
  • Loading branch information
Aloento committed Jun 5, 2024
1 parent 9547f1b commit e0e2277
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def get(self, search_args):
cached_component = get_elements_from_cache(cache_key)
if cached_component:
current_app.logger.debug("The response was cached")
return [cached_component]
return cached_component

if attribute_name is not None and attribute_value is not None:
target_component = Component.find_by_name_and_attributes(
Expand All @@ -268,7 +268,7 @@ def get(self, search_args):
abort(404, message="Component does not exist")
serialized_component = component_schema.dump(target_component)
cache.set(cache_key, serialized_component)
return [serialized_component]
return serialized_component

components = db.session.scalars(
db.select(Component).filter(Component.name.startswith(name))
Expand All @@ -277,7 +277,7 @@ def get(self, search_args):
abort(404, message="Component(s) does not (do not) exist")
serialized_components = component_schema.dump(components, many=True)
cache.set(cache_key, serialized_components)
return [serialized_components]
return serialized_components

@bp.arguments(ComponentStatusArgsSchema)
@auth.login_required
Expand Down

0 comments on commit e0e2277

Please sign in to comment.