From 0d95a56f7f487ad21273552eb6a875a5d4fda4aa Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Fri, 16 May 2025 12:08:15 +0800 Subject: [PATCH] perf: Refine the Model Manager code --- apps/common/util/rsa_util.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/common/util/rsa_util.py b/apps/common/util/rsa_util.py index 00301867208..452ca678d9e 100644 --- a/apps/common/util/rsa_util.py +++ b/apps/common/util/rsa_util.py @@ -40,15 +40,12 @@ def generate(): def get_key_pair(): rsa_value = rsa_cache.get(cache_key) if rsa_value is None: - lock.acquire() - rsa_value = rsa_cache.get(cache_key) - if rsa_value is not None: - return rsa_value - try: + with lock: + rsa_value = rsa_cache.get(cache_key) + if rsa_value is not None: + return rsa_value rsa_value = get_key_pair_by_sql() rsa_cache.set(cache_key, rsa_value) - finally: - lock.release() return rsa_value