Skip to content

Commit

Permalink
perf(dependencies): skip doing any work when sub dependant is already…
Browse files Browse the repository at this point in the history
… cached
  • Loading branch information
xkabylgSICKAG committed Mar 20, 2024
1 parent 957845d commit 8bb7d6d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fastapi/dependencies/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,16 @@ async def solve_dependencies(
sub_dependant.cache_key = cast(
Tuple[Callable[..., Any], Tuple[str]], sub_dependant.cache_key
)

# If the dependant is already cached, skip doing any work here
if (
sub_dependant.use_cache
and sub_dependant.cache_key in dependency_cache
and sub_dependant.name is not None
):
values[sub_dependant.name] = dependency_cache[sub_dependant.cache_key]
continue

call = sub_dependant.call
use_sub_dependant = sub_dependant
if (
Expand Down

0 comments on commit 8bb7d6d

Please sign in to comment.