2828from .models import ProjectDict , ProjectTypeAPI
2929
3030
31- async def _update_project_dict (
31+ async def _batch_update_list_of_project_dict (
32+ app : web .Application , list_of_project_dict : list [ProjectDict ]
33+ ) -> list [ProjectDict ]:
34+
35+ # updating `trashed_by_primary_gid`
36+ trashed_by_primary_gid_values = await batch_get_trashed_by_primary_gid (
37+ app , projects_uuids = [ProjectID (p ["uuid" ]) for p in list_of_project_dict ]
38+ )
39+
40+ for project_dict , value in zip (
41+ list_of_project_dict , trashed_by_primary_gid_values , strict = True
42+ ):
43+ project_dict .update (trashed_by_primary_gid = value )
44+
45+ return list_of_project_dict
46+
47+
48+ async def _update_and_get_project_dict (
3249 request : web .Request ,
3350 * ,
3451 user_id : UserID ,
@@ -49,23 +66,6 @@ async def _update_project_dict(
4966 return project
5067
5168
52- async def _batch_update_list_of_project_dict (
53- app : web .Application , list_of_project_dict : list [ProjectDict ]
54- ) -> list [ProjectDict ]:
55-
56- # updating `trashed_by_primary_gid`
57- trashed_by_primary_gid_values = await batch_get_trashed_by_primary_gid (
58- app , projects_uuids = [ProjectID (p ["uuid" ]) for p in list_of_project_dict ]
59- )
60-
61- for project_dict , value in zip (
62- list_of_project_dict , trashed_by_primary_gid_values , strict = True
63- ):
64- project_dict .update (trashed_by_primary_gid = value )
65-
66- return list_of_project_dict
67-
68-
6969async def list_projects ( # pylint: disable=too-many-arguments
7070 request : web .Request ,
7171 user_id : UserID ,
@@ -145,11 +145,13 @@ async def list_projects( # pylint: disable=too-many-arguments
145145 order_by = order_by ,
146146 )
147147
148+ # AGGREGATE data to the project from other sources, first some sources
149+ # as batch-update and then as parallel-update
148150 db_projects = await _batch_update_list_of_project_dict (app , db_projects )
149151
150152 projects : list [ProjectDict ] = await logged_gather (
151153 * (
152- _update_project_dict (
154+ _update_and_get_project_dict (
153155 request ,
154156 user_id = user_id ,
155157 project = prj ,
@@ -165,7 +167,7 @@ async def list_projects( # pylint: disable=too-many-arguments
165167
166168
167169async def list_projects_full_depth (
168- request ,
170+ app : web . Application ,
169171 * ,
170172 user_id : UserID ,
171173 product_name : str ,
@@ -180,10 +182,10 @@ async def list_projects_full_depth(
180182 search_by_multi_columns : str | None ,
181183 search_by_project_name : str | None ,
182184) -> tuple [list [ProjectDict ], int ]:
183- db = ProjectDBAPI .get_from_app_context (request . app )
185+ db = ProjectDBAPI .get_from_app_context (app )
184186
185187 user_available_services : list [dict ] = await get_services_for_user_in_product (
186- request . app , user_id , product_name , only_key_versions = True
188+ app , user_id , product_name , only_key_versions = True
187189 )
188190
189191 db_projects , db_project_types , total_number_projects = await db .list_projects_dicts (
@@ -202,15 +204,18 @@ async def list_projects_full_depth(
202204 order_by = order_by ,
203205 )
204206
205- db_projects = await _batch_update_list_of_project_dict (request .app , db_projects )
207+ # AGGREGATE data to the project from other sources, first some sources
208+ # as BATCH-update and then as PARALLEL-update
209+ db_projects = await _batch_update_list_of_project_dict (app , db_projects )
206210
207211 projects : list [ProjectDict ] = await logged_gather (
208212 * (
209- _update_project_dict (
210- request ,
213+ # state
214+ projects_service . add_project_states_for_user (
211215 user_id = user_id ,
212216 project = prj ,
213217 is_template = prj_type == ProjectTypeDB .TEMPLATE ,
218+ app = app ,
214219 )
215220 for prj , prj_type in zip (db_projects , db_project_types , strict = False )
216221 ),
0 commit comments