@@ -113,23 +113,23 @@ async def get_by_project(
113113 projects_nodes .c .project_uuid == f"{ project_id } "
114114 )
115115
116- result = await conn .stream (query )
117- assert result # nosec
116+ stream = await conn .stream (query )
117+ assert stream # nosec
118118
119- rows = await result .all ()
120- return [
121- (
122- NodeID (row .node_id ),
123- Node .model_validate (
124- ProjectNode .model_validate (row , from_attributes = True ).model_dump (
125- exclude_none = True ,
126- exclude_unset = True ,
127- exclude = {"node_id" , "created" , "modified" },
128- )
129- ),
119+ result : list [tuple [NodeID , Node ]] = []
120+ async for row in stream :
121+ # build Model only once on top of row
122+ pn = ProjectNode .model_validate (row , from_attributes = True )
123+ node = Node .model_validate (
124+ pn .model_dump (
125+ exclude_none = True ,
126+ exclude_unset = True ,
127+ exclude = {"node_id" , "created" , "modified" },
128+ )
130129 )
131- for row in rows
132- ]
130+ result .append ((NodeID (row .node_id ), node ))
131+
132+ return result
133133
134134
135135async def get_by_projects (
@@ -145,18 +145,16 @@ async def get_by_projects(
145145 projects_nodes .c .project_uuid .in_ ([f"{ pid } " for pid in project_ids ])
146146 )
147147
148- result = await conn .stream (query )
149- assert result # nosec
150-
151- rows = await result .all ()
148+ stream = await conn .stream (query )
149+ assert stream # nosec
152150
153151 # Initialize dict with empty lists for all requested project_ids
154152 projects_to_nodes : dict [ProjectID , list [tuple [NodeID , Node ]]] = {
155153 pid : [] for pid in project_ids
156154 }
157155
158156 # Fill in the actual data
159- for row in rows :
157+ async for row in stream :
160158 node = Node .model_validate (
161159 ProjectNode .model_validate (row ).model_dump (
162160 exclude_none = True ,
0 commit comments