@@ -532,6 +532,17 @@ def filter_functions(
532532 disable_logs : bool = False , # noqa: FBT001, FBT002
533533) -> tuple [dict [Path , list [FunctionToOptimize ]], int ]:
534534 blocklist_funcs = get_blocklisted_functions ()
535+ already_optimized_count = 0
536+ path_based_functions = {Path (k ): v for k , v in modified_functions .items () if v }
537+ try :
538+ repository = git .Repo (Path .cwd (), search_parent_directories = True )
539+ owner , repo = get_repo_owner_and_name (repository )
540+ except git .exc .InvalidGitRepositoryError :
541+ logger .warning ("No git repository found" )
542+ owner , repo = None , None
543+ pr_number = get_pr_number ()
544+ if owner and repo and pr_number is not None :
545+ path_based_functions , functions_count = check_optimization_status (path_based_functions , owner , repo , pr_number )
535546 logger .debug (f"Blocklisted functions: { blocklist_funcs } " )
536547 # Remove any function that we don't want to optimize
537548
@@ -606,19 +617,10 @@ def filter_functions(
606617 functions_count += len (_functions )
607618
608619 # Convert to Path keys for optimization check
609- path_based_functions = { Path ( k ): v for k , v in filtered_modified_functions . items () if v }
620+
610621
611622 # Check optimization status if repository info is provided
612- already_optimized_count = 0
613- try :
614- repository = git .Repo (Path .cwd (), search_parent_directories = True )
615- owner , repo = get_repo_owner_and_name (repository )
616- except git .exc .InvalidGitRepositoryError :
617- logger .warning ("No git repository found" )
618- owner , repo = None , None
619- pr_number = get_pr_number ()
620- if owner and repo and pr_number is not None :
621- path_based_functions , functions_count = check_optimization_status (path_based_functions , owner , repo , pr_number )
623+
622624 initial_count = sum (len (funcs ) for funcs in filtered_modified_functions .values ())
623625 already_optimized_count = initial_count - functions_count
624626
0 commit comments