From ba8aa6e4ddcf075eb0984417a2b66416bc7b2efb Mon Sep 17 00:00:00 2001 From: s_kovalev Date: Mon, 20 May 2024 16:34:41 +0400 Subject: [PATCH] cache cattrs converter to prevent memory leak --- appstoreserverlibrary/models/LibraryUtility.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appstoreserverlibrary/models/LibraryUtility.py b/appstoreserverlibrary/models/LibraryUtility.py index 31add6c..efa20e0 100644 --- a/appstoreserverlibrary/models/LibraryUtility.py +++ b/appstoreserverlibrary/models/LibraryUtility.py @@ -1,6 +1,7 @@ # Copyright (c) 2023 Apple Inc. Licensed under MIT License. from enum import EnumMeta +from functools import lru_cache from typing import Any, List, Type, TypeVar from attr import Attribute, has, ib, fields @@ -52,7 +53,8 @@ def __attrs_post_init__(self): elif value is not None: setattr(self, field, value) - + +@lru_cache(maxsize=None) def _get_cattrs_converter(destination_class: Type[T]) -> cattrs.Converter: c = cattrs.Converter() attributes: List[Attribute] = fields(destination_class)