From 8d3d93e537d2b1440463c6fb3038bb30a3dc158f Mon Sep 17 00:00:00 2001
From: dhb52 <dhb52@126.com>
Date: 星期二, 02 一月 2024 23:15:08 +0800
Subject: [PATCH] perf: 减少powerjob不必要的代理路径

---
 ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java
index 084d89a..763b090 100644
--- a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java
+++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java
@@ -39,23 +39,25 @@
     /**
      * 鏍规嵁绫诲瀷鑾峰彇瀹炰緥
      */
-    public static OssClient instance(String configKey) {
+    public static synchronized OssClient instance(String configKey) {
         String json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey);
         if (json == null) {
             throw new OssException("绯荤粺寮傚父, '" + configKey + "'閰嶇疆淇℃伅涓嶅瓨鍦�!");
         }
         OssProperties properties = JsonUtils.parseObject(json, OssProperties.class);
-        OssClient client = CLIENT_CACHE.get(configKey);
+        // 浣跨敤绉熸埛鏍囪瘑閬垮厤澶氫釜绉熸埛鐩稿悓key瀹炰緥瑕嗙洊
+        String key = properties.getTenantId() + ":" + configKey;
+        OssClient client = CLIENT_CACHE.get(key);
         if (client == null) {
-            CLIENT_CACHE.put(configKey, new OssClient(configKey, properties));
+            CLIENT_CACHE.put(key, new OssClient(configKey, properties));
             log.info("鍒涘缓OSS瀹炰緥 key => {}", configKey);
-            return CLIENT_CACHE.get(configKey);
+            return CLIENT_CACHE.get(key);
         }
         // 閰嶇疆涓嶇浉鍚屽垯閲嶆柊鏋勫缓
         if (!client.checkPropertiesSame(properties)) {
-            CLIENT_CACHE.put(configKey, new OssClient(configKey, properties));
+            CLIENT_CACHE.put(key, new OssClient(configKey, properties));
             log.info("閲嶈浇OSS瀹炰緥 key => {}", configKey);
-            return CLIENT_CACHE.get(configKey);
+            return CLIENT_CACHE.get(key);
         }
         return client;
     }

--
Gitblit v1.9.3