-
Notifications
You must be signed in to change notification settings - Fork 232
[app-builder] 优化部分性能,添加流程数据定时清理机制 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
233d9f8
4f5c8b6
cc35ed4
fb1d465
85466ce
6112350
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,16 @@ | |
| import modelengine.fit.jade.waterflow.FlowsService; | ||
| import modelengine.fit.jade.waterflow.dto.FlowInfo; | ||
| import modelengine.fit.jane.common.entity.OperationContext; | ||
| import modelengine.fit.jane.meta.multiversion.MetaService; | ||
| import modelengine.fit.jane.meta.multiversion.definition.Meta; | ||
| import modelengine.fit.jober.aipp.common.exception.AippErrCode; | ||
| import modelengine.fit.jober.aipp.common.exception.AippException; | ||
| import modelengine.fit.jober.aipp.po.AppBuilderAppPo; | ||
| import modelengine.fitframework.annotation.Component; | ||
| import modelengine.fitframework.util.CollectionUtils; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
|
|
@@ -50,29 +57,70 @@ public class CacheUtils { | |
| .maximumSize(1000) | ||
| .build(); | ||
|
|
||
| /** | ||
| * 用于缓存app_id和meta的关系 | ||
| */ | ||
| public static final Cache<String, Meta> AIPP_ID_LAST_META_CACHE = Caffeine.newBuilder() | ||
| .expireAfterAccess(5, TimeUnit.SECONDS) | ||
| .maximumSize(1000) | ||
| .build(); | ||
|
|
||
| /** | ||
| * 清理缓存 | ||
| */ | ||
| public static void clear() { | ||
| APP_CACHE.invalidateAll(); | ||
| FLOW_CACHE.invalidateAll(); | ||
| APP_ID_TO_AIPP_ID_CACHE.invalidateAll(); | ||
| AIPP_ID_LAST_META_CACHE.invalidateAll(); | ||
|
|
||
| APP_CACHE.cleanUp(); | ||
| FLOW_CACHE.cleanUp(); | ||
| APP_ID_TO_AIPP_ID_CACHE.cleanUp(); | ||
| AIPP_ID_LAST_META_CACHE.cleanUp(); | ||
| } | ||
|
|
||
| /** | ||
| * 用于获取flowdefinition的缓存 | ||
| * | ||
| * @param flowsService 操作flow的service | ||
| * @param flowsService 操作flow的service | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * @param flowDefinitionId 缓存的flowDefinition的id | ||
| * @param context 人员上下文 | ||
| * @param context 人员上下文 | ||
| * @return 缓存的FlowInfo | ||
| */ | ||
| public static FlowInfo getPublishedFlowWithCache(FlowsService flowsService, String flowDefinitionId, | ||
| OperationContext context) { | ||
| return FLOW_CACHE.get(flowDefinitionId, id -> flowsService.getFlows(id, context)); | ||
| } | ||
|
|
||
| /** | ||
| * 根据appId查询对应meta | ||
| * | ||
| * @param metaService 用于查询meta的服务实例 | ||
| * @param appId 应用appId | ||
| * @param isDebug 是否为debug会话 | ||
| * @param context 操作上下文 | ||
| * @return app对应的meta信息 | ||
| */ | ||
| public static Meta getMetaByAppId(MetaService metaService, String appId, boolean isDebug, | ||
| OperationContext context) { | ||
| if (isDebug) { | ||
| return getLatestMetaByAppId(metaService, appId, context); | ||
| } | ||
| // get一个aipp_id的缓存,然后根据aipp_id查询最新发布版的meta | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| String aippId = APP_ID_TO_AIPP_ID_CACHE.get(appId, id -> getLatestMetaByAppId(metaService, id, context).getId()); | ||
| return AIPP_ID_LAST_META_CACHE.get(aippId, (ignore) -> { | ||
| Meta lastPublishedMeta = MetaUtils.getLastPublishedMeta(metaService, appId, context); | ||
| return Optional.ofNullable(lastPublishedMeta) | ||
| .orElseThrow(() -> new AippException(AippErrCode.APP_CHAT_PUBLISHED_META_NOT_FOUND)); | ||
| }); | ||
| } | ||
|
|
||
| private static Meta getLatestMetaByAppId(MetaService metaService, String appId, OperationContext context) { | ||
| List<Meta> metas = MetaUtils.getAllMetasByAppId(metaService, appId, context); | ||
| if (CollectionUtils.isEmpty(metas)) { | ||
| throw new AippException(AippErrCode.APP_CHAT_DEBUG_META_NOT_FOUND); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| return metas.get(0); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import lombok.NoArgsConstructor; | ||
| import modelengine.fit.jober.aipp.constants.AippConst; | ||
| import modelengine.fitframework.annotation.Property; | ||
| import modelengine.fitframework.util.StringUtils; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
|
|
@@ -38,6 +39,15 @@ public class CreateAppChatRequest { | |
| @Property(description = "context", name = "context") | ||
| private Context context; | ||
|
|
||
| /** | ||
| * 判断是否有@应用 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * | ||
| * @return true-有; false-没有 | ||
| */ | ||
| public boolean hasAtOtherApp() { | ||
| return StringUtils.isNotBlank(getContext().getAtChatId()) || StringUtils.isNotBlank(getContext().getAtAppId()); | ||
| } | ||
|
|
||
| /** | ||
| * 本类表示对话的上下文 | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.fit.waterflow.common.utils; | ||
|
|
||
| import java.util.UUID; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
|
|
||
| /** | ||
| * Uuid的Utils类。 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * | ||
| * @author 孙怡菲 | ||
| * @since 1.0 | ||
| */ | ||
| public class UUIDUtil { | ||
| /** | ||
| * 随机生成uuid。 | ||
| * | ||
| * @return 随机生成的uuid的 {@link String}。 | ||
| */ | ||
| public static String uuid() { | ||
| return UUID.randomUUID().toString().replace("-", ""); | ||
| } | ||
|
|
||
| /** | ||
| * 使用线程本地随机数生成UUID。 | ||
| * 生成的 UUID 在唯一性和不可预测性上可能不如 UUID.randomUUID(),但在性能上有显著提升 | ||
| * | ||
| * @return 生成的UUID。 | ||
| */ | ||
| public static String fastUuid() { | ||
| long mostSigBits = ThreadLocalRandom.current().nextLong(); | ||
| long leastSigBits = ThreadLocalRandom.current().nextLong(); | ||
|
|
||
| // 设置版本4和变体IETF | ||
| mostSigBits &= 0xffffffffffff0fffL; | ||
| mostSigBits |= 0x0000000000004000L; | ||
| leastSigBits &= 0x3fffffffffffffffL; | ||
| leastSigBits |= 0x8000000000000000L; | ||
|
|
||
| return new UUID(mostSigBits, leastSigBits).toString().replace("-", ""); | ||
| } | ||
| } | ||





There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAST是什么意思?private,然后仅通过方法来访问?而不是公开了之后支持任意访问