@@ -287,7 +287,6 @@ async def shutdown(self) -> None:
287287 await self ._event_service .shutdown ()
288288 logger .info ("Tool service shutdown complete" )
289289
290-
291290 async def get_top_tools (self , db : Session , limit : Optional [int ] = 5 ) -> List [TopPerformer ]:
292291 """Retrieve the top-performing tools based on execution count.
293292
@@ -309,21 +308,13 @@ async def get_top_tools(self, db: Session, limit: Optional[int] = 5) -> List[Top
309308 - last_execution: Timestamp of the last execution, or None if no metrics.
310309 """
311310
312- success_rate = case (
313- (
314- func .count (ToolMetric .id ) > 0 ,
315- func .sum (
316- case ((ToolMetric .is_success .is_ (True ), 1 ), else_ = 0 )
317- ).cast (Float ) * 100 / func .count (ToolMetric .id )
318- ),
319- else_ = None
320- )
311+ success_rate = case ((func .count (ToolMetric .id ) > 0 , func .sum (case ((ToolMetric .is_success .is_ (True ), 1 ), else_ = 0 )).cast (Float ) * 100 / func .count (ToolMetric .id )), else_ = None ) # pylint: disable=not-callable
321312
322313 query = (
323314 select (
324315 DbTool .id ,
325316 DbTool .name ,
326- func .count (ToolMetric .id ).label ("execution_count" ),
317+ func .count (ToolMetric .id ).label ("execution_count" ), # pylint: disable=not-callable
327318 func .avg (ToolMetric .response_time ).label ("avg_response_time" ),
328319 success_rate .label ("success_rate" ),
329320 func .max (ToolMetric .timestamp ).label ("last_execution" ),
@@ -390,7 +381,7 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T
390381 "token" : "********" if decoded_auth_value ["Authorization" ] else None ,
391382 }
392383 elif tool .auth_type == "authheaders" :
393- # Get first key
384+ # Get first key
394385 first_key = next (iter (decoded_auth_value ))
395386 tool_dict ["auth" ] = {
396387 "auth_type" : "authheaders" ,
@@ -414,7 +405,6 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T
414405 tool_dict ["team" ] = getattr (tool , "team" , None )
415406 return ToolRead .model_validate (tool_dict )
416407
417-
418408 async def _record_tool_metric (self , db : Session , tool : DbTool , start_time : float , success : bool , error_message : Optional [str ]) -> None :
419409 """
420410 Records a metric for a tool invocation.
@@ -958,14 +948,14 @@ async def list_tools_for_user(
958948 # query = query.offset(skip).limit(limit)
959949
960950 tools = db .execute (query ).scalars ().all ()
961-
951+
962952 # Batch fetch team names for all tools at once
963953 tool_team_ids = {getattr (t , "team_id" , None ) for t in tools if getattr (t , "team_id" , None )}
964954 team_name_map = {}
965955 if tool_team_ids :
966956 teams = db .query (EmailTeam .id , EmailTeam .name ).filter (EmailTeam .id .in_ (tool_team_ids ), EmailTeam .is_active .is_ (True )).all ()
967957 team_name_map = {team .id : team .name for team in teams }
968-
958+
969959 result = []
970960 for t in tools :
971961 team_name = team_name_map .get (getattr (t , "team_id" , None ))
0 commit comments