From 4954d3978cf1967729a5a2d5b90f6baef18974da Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期一, 23 三月 2026 09:35:10 +0800
Subject: [PATCH] #ai redis+页面优化
---
rsf-server/src/main/java/com/vincent/rsf/server/ai/service/impl/AiMcpMountServiceImpl.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/ai/service/impl/AiMcpMountServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/ai/service/impl/AiMcpMountServiceImpl.java
index f09b0fa..409c20f 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/ai/service/impl/AiMcpMountServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/ai/service/impl/AiMcpMountServiceImpl.java
@@ -35,6 +35,7 @@
private final BuiltinMcpToolRegistry builtinMcpToolRegistry;
private final McpMountRuntimeFactory mcpMountRuntimeFactory;
private final ObjectMapper objectMapper;
+ private final AiRedisSupport aiRedisSupport;
/** 鏌ヨ鏌愪釜绉熸埛涓嬪綋鍓嶅惎鐢ㄧ殑 MCP 鎸傝浇鍒楄〃銆� */
@Override
@@ -77,6 +78,11 @@
@Override
public List<AiMcpToolPreviewDto> previewTools(Long mountId, Long userId, Long tenantId) {
AiMcpMount mount = requireMount(mountId, tenantId);
+ // 宸ュ叿鐩綍棰勮鍒濆鍖栨垚鏈珮锛屼絾鍙樺寲棰戠巼浣庯紝閫傚悎鍋氱鐞嗙鐭紦瀛樸��
+ List<AiMcpToolPreviewDto> cached = aiRedisSupport.getToolPreview(tenantId, mountId);
+ if (cached != null) {
+ return cached;
+ }
long startedAt = System.currentTimeMillis();
try (McpMountRuntimeFactory.McpMountRuntime runtime = mcpMountRuntimeFactory.create(List.of(mount), userId)) {
List<AiMcpToolPreviewDto> tools = buildToolPreviewDtos(runtime.getToolCallbacks(),
@@ -90,6 +96,7 @@
}
updateHealthStatus(mount.getId(), AiDefaults.MCP_HEALTH_HEALTHY,
"宸ュ叿瑙f瀽鎴愬姛锛屽叡 " + tools.size() + " 涓伐鍏�", System.currentTimeMillis() - startedAt);
+ aiRedisSupport.cacheToolPreview(tenantId, mountId, tools);
return tools;
} catch (CoolException e) {
throw e;
@@ -111,12 +118,16 @@
String message = String.join("锛�", runtime.getErrors());
updateHealthStatus(mount.getId(), AiDefaults.MCP_HEALTH_UNHEALTHY, message, elapsedMs);
AiMcpMount latest = requireMount(mount.getId(), tenantId);
- return buildConnectivityDto(latest, message, elapsedMs, runtime.getToolCallbacks().length);
+ AiMcpConnectivityTestDto connectivity = buildConnectivityDto(latest, message, elapsedMs, runtime.getToolCallbacks().length);
+ aiRedisSupport.cacheConnectivity(tenantId, mountId, connectivity);
+ return connectivity;
}
String message = "杩為�氭�ф祴璇曟垚鍔燂紝瑙f瀽鍑� " + runtime.getToolCallbacks().length + " 涓伐鍏�";
updateHealthStatus(mount.getId(), AiDefaults.MCP_HEALTH_HEALTHY, message, elapsedMs);
AiMcpMount latest = requireMount(mount.getId(), tenantId);
- return buildConnectivityDto(latest, message, elapsedMs, runtime.getToolCallbacks().length);
+ AiMcpConnectivityTestDto connectivity = buildConnectivityDto(latest, message, elapsedMs, runtime.getToolCallbacks().length);
+ aiRedisSupport.cacheConnectivity(tenantId, mountId, connectivity);
+ return connectivity;
} catch (CoolException e) {
throw e;
} catch (Exception e) {
@@ -124,7 +135,9 @@
String message = "杩為�氭�ф祴璇曞け璐�: " + e.getMessage();
updateHealthStatus(mount.getId(), AiDefaults.MCP_HEALTH_UNHEALTHY, message, elapsedMs);
AiMcpMount latest = requireMount(mount.getId(), tenantId);
- return buildConnectivityDto(latest, message, elapsedMs, 0);
+ AiMcpConnectivityTestDto connectivity = buildConnectivityDto(latest, message, elapsedMs, 0);
+ aiRedisSupport.cacheConnectivity(tenantId, mountId, connectivity);
+ return connectivity;
}
}
@@ -227,6 +240,40 @@
}
}
+ @Override
+ public boolean save(AiMcpMount entity) {
+ boolean saved = super.save(entity);
+ if (saved && entity != null && entity.getTenantId() != null) {
+ aiRedisSupport.evictMcpMountCaches(entity.getTenantId(), entity.getId());
+ }
+ return saved;
+ }
+
+ @Override
+ public boolean updateById(AiMcpMount entity) {
+ boolean updated = super.updateById(entity);
+ if (updated && entity != null && entity.getTenantId() != null) {
+ aiRedisSupport.evictMcpMountCaches(entity.getTenantId(), entity.getId());
+ }
+ return updated;
+ }
+
+ @Override
+ public boolean removeByIds(java.util.Collection<?> list) {
+ java.util.List<java.io.Serializable> ids = list == null ? java.util.List.of() : list.stream()
+ .filter(java.util.Objects::nonNull)
+ .map(item -> (java.io.Serializable) item)
+ .toList();
+ java.util.List<AiMcpMount> records = this.listByIds(ids);
+ boolean removed = super.removeByIds(list);
+ if (removed) {
+ records.stream()
+ .filter(java.util.Objects::nonNull)
+ .forEach(item -> aiRedisSupport.evictMcpMountCaches(item.getTenantId(), item.getId()));
+ }
+ return removed;
+ }
+
private void fillDefaults(AiMcpMount aiMcpMount) {
/** 涓烘寕杞借崏绋胯ˉ榻愮粺涓�榛樿鍊硷紝淇濊瘉鍚庣画杩愯鏃朵唬鐮佷笉闇�瑕侀噸澶嶅垽鏂┖鍊笺�� */
if (!StringUtils.hasText(aiMcpMount.getTransportType())) {
--
Gitblit v1.9.1