Skip to content

Commit

Permalink
feat: adds total_count to collection responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Nov 22, 2022
1 parent 99a1a9e commit 475483d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Bumps `uwsgi` from `2.0.20` to `2.0.21` unlocking Python 3.10 and 3.11 support
- Changes from process/threads concurrency to dynamic worker concurrency with uwsgi
- Added timeouts and worker kill commands so Harvey will canabolize itself instead of the OS
- Adds `total_count` to collection responses

## v0.20.1 (2022-07-26)

Expand Down
10 changes: 7 additions & 3 deletions harvey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def retrieve_deployment(deployment_id: str) -> Dict[str, Any]:
@staticmethod
def retrieve_deployments(request: flask.Request) -> Dict[str, List[Any]]:
"""Retrieve a list of deployments until the pagination limit is reached."""
deployments: Dict[str, List[Any]] = {'deployments': []}
deployments: Dict[str, Any] = {'deployments': []}

page_size = Api._page_size(request)
project_name = request.args.get('project')
Expand All @@ -166,14 +166,15 @@ def retrieve_deployments(request: flask.Request) -> Dict[str, List[Any]]:
pass

sorted_deployments = sorted(deployments['deployments'], key=lambda i: i['timestamp'], reverse=True)[:page_size]
deployments['total_count'] = len(deployments['deployments'])
deployments['deployments'] = sorted_deployments

return deployments

@staticmethod
def retrieve_projects(request: flask.Request) -> Dict[str, List[Any]]:
"""Retrieve a list of projects stored in Harvey by scanning the `projects` directory."""
projects: Dict[str, List[str]] = {'projects': []}
projects: Dict[str, Any] = {'projects': []}
project_owners = os.listdir(Config.projects_path)
page_size = Api._page_size(request)

Expand All @@ -190,11 +191,13 @@ def retrieve_projects(request: flask.Request) -> Dict[str, List[Any]]:
if len(projects['projects']) > page_size:
break

projects['total_count'] = len(projects['projects'])

return projects

@staticmethod
def retrieve_locks(request: flask.Request) -> Dict[str, List[Any]]:
locks: Dict[str, List[Any]] = {'locks': []}
locks: Dict[str, Any] = {'locks': []}

page_size = Api._page_size(request)

Expand All @@ -208,6 +211,7 @@ def retrieve_locks(request: flask.Request) -> Dict[str, List[Any]]:
)

sorted_locks = sorted(locks['locks'], key=lambda x: x['project'])[:page_size]
locks['total_count'] = len(locks['locks'])
locks['locks'] = sorted_locks

return locks
Expand Down

0 comments on commit 475483d

Please sign in to comment.