Fix projects.get_all_ex

This commit is contained in:
allegroai 2022-09-29 19:20:50 +03:00
parent 8d4c02fc3c
commit b871bf4224

View File

@ -130,27 +130,25 @@ def get_all_ex(call: APICall, company_id: str, request: ProjectsGetRequest):
allow_public=allow_public, allow_public=allow_public,
ret_params=ret_params, ret_params=ret_params,
) )
if not projects:
return {"projects": projects, **ret_params}
if request.check_own_contents and requested_ids: project_ids = list({project["id"] for project in projects})
existing_requested_ids = { if request.check_own_contents:
project["id"] for project in projects if project["id"] in requested_ids contents = project_bll.calc_own_contents(
} company=company_id,
if existing_requested_ids: project_ids=project_ids,
contents = project_bll.calc_own_contents( filter_=request.include_stats_filter,
company=company_id, users=request.active_users,
project_ids=list(existing_requested_ids), )
filter_=request.include_stats_filter, for project in projects:
users=request.active_users, project.update(**contents.get(project["id"], {}))
)
for project in projects:
project.update(**contents.get(project["id"], {}))
conform_output_tags(call, projects) conform_output_tags(call, projects)
if request.include_stats: if request.include_stats:
project_ids = {project["id"] for project in projects}
stats, children = project_bll.get_project_stats( stats, children = project_bll.get_project_stats(
company=company_id, company=company_id,
project_ids=list(project_ids), project_ids=project_ids,
specific_state=request.stats_for_state, specific_state=request.stats_for_state,
include_children=request.stats_with_children, include_children=request.stats_with_children,
search_hidden=request.search_hidden, search_hidden=request.search_hidden,
@ -164,10 +162,9 @@ def get_all_ex(call: APICall, company_id: str, request: ProjectsGetRequest):
project["sub_projects"] = children[project["id"]] project["sub_projects"] = children[project["id"]]
if request.include_dataset_stats: if request.include_dataset_stats:
project_ids = {project["id"] for project in projects}
dataset_stats = project_bll.get_dataset_stats( dataset_stats = project_bll.get_dataset_stats(
company=company_id, company=company_id,
project_ids=list(project_ids), project_ids=project_ids,
users=request.active_users, users=request.active_users,
) )
for project in projects: for project in projects: