Skip to content

Commit f96b029

Browse files
committed
perf: Use the lru cache when fetching model_fields in the pydantic v2 model to improve performance
1 parent 2ed687e commit f96b029

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

fastapi_amis_admin/utils/pydantic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
from functools import lru_cache
23
from typing import Any, Dict, Optional, Sequence, Set, Type, Union
34

45
from fastapi._compat import ( # noqa: F401
@@ -71,6 +72,7 @@ def field_allow_none(field: ModelField) -> bool:
7172
return True
7273
return False
7374

75+
@lru_cache(maxsize=512)
7476
def model_fields(model: Type[BaseModel]) -> Dict[str, ModelField]:
7577
fields = {}
7678
for field_name, field in model.model_fields.items():

0 commit comments

Comments
 (0)