mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-05 01:02:59 +08:00
V4.14.4 features (#6075)
* perf: faq * index * delete dataset * delete dataset * perf: delete dataset * init * fix: faq * refresh * empty tip * perf: delete type * fix: some bugs (#6071) * fix: publish channel doc link * fix: checkbox disable hover style * fix: huggingface.svg missing; update doc * chore: update doc * fix: typo * fix: export log dateend;feat: file selector render (#6072) * fix: export log dateend * feat: file selector render * perf: s3 controller * team qpm limit & plan tracks (#6066) * team qpm limit & plan tracks * api entry qpm * perf: computed days * Revert "api entry qpm" This reverts commit 1210c07217ab4509d54b3eb57067dd94ff8b0da6. * perf: code * system qpm limit * system qpm limit --------- Co-authored-by: archer <545436317@qq.com> * perf: track * remove export chat test * doc * feat: global agent (#6057) * feat: global agent * fix: agent * fix: order display * CHORE * feat: error page log * fix: var update --------- Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com> Co-authored-by: heheer <heheer@sealos.io> Co-authored-by: Roy <whoeverimf5@gmail.com>
This commit is contained in:
@@ -190,7 +190,7 @@ export const getTeamPlanStatus = async ({
|
||||
? standardPlans[standardPlan.currentSubLevel]
|
||||
: undefined;
|
||||
|
||||
updateTeamPointsCache({ teamId, totalPoints, surplusPoints });
|
||||
teamPoint.updateTeamPointsCache({ teamId, totalPoints, surplusPoints });
|
||||
|
||||
return {
|
||||
[SubTypeEnum.standard]: standardPlan,
|
||||
@@ -223,58 +223,99 @@ export const getTeamPlanStatus = async ({
|
||||
};
|
||||
};
|
||||
|
||||
export const clearTeamPointsCache = async (teamId: string) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
const totalCacheKey = `${CacheKeyEnum.team_point_total}:${teamId}`;
|
||||
export const teamPoint = {
|
||||
getTeamPoints: async ({ teamId }: { teamId: string }) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
const totalCacheKey = `${CacheKeyEnum.team_point_total}:${teamId}`;
|
||||
|
||||
await Promise.all([delRedisCache(surplusCacheKey), delRedisCache(totalCacheKey)]);
|
||||
};
|
||||
const [surplusCacheStr, totalCacheStr] = await Promise.all([
|
||||
getRedisCache(surplusCacheKey),
|
||||
getRedisCache(totalCacheKey)
|
||||
]);
|
||||
|
||||
export const incrTeamPointsCache = async ({ teamId, value }: { teamId: string; value: number }) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
await incrValueToCache(surplusCacheKey, value);
|
||||
};
|
||||
export const updateTeamPointsCache = async ({
|
||||
teamId,
|
||||
totalPoints,
|
||||
surplusPoints
|
||||
}: {
|
||||
teamId: string;
|
||||
totalPoints: number;
|
||||
surplusPoints: number;
|
||||
}) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
const totalCacheKey = `${CacheKeyEnum.team_point_total}:${teamId}`;
|
||||
if (surplusCacheStr && totalCacheStr) {
|
||||
const totalPoints = Number(totalCacheStr);
|
||||
const surplusPoints = Number(surplusCacheStr);
|
||||
return {
|
||||
totalPoints,
|
||||
surplusPoints,
|
||||
usedPoints: totalPoints - surplusPoints
|
||||
};
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
setRedisCache(surplusCacheKey, surplusPoints, CacheKeyEnumTime.team_point_surplus),
|
||||
setRedisCache(totalCacheKey, totalPoints, CacheKeyEnumTime.team_point_total)
|
||||
]);
|
||||
};
|
||||
|
||||
export const getTeamPoints = async ({ teamId }: { teamId: string }) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
const totalCacheKey = `${CacheKeyEnum.team_point_total}:${teamId}`;
|
||||
|
||||
const [surplusCacheStr, totalCacheStr] = await Promise.all([
|
||||
getRedisCache(surplusCacheKey),
|
||||
getRedisCache(totalCacheKey)
|
||||
]);
|
||||
|
||||
if (surplusCacheStr && totalCacheStr) {
|
||||
const totalPoints = Number(totalCacheStr);
|
||||
const surplusPoints = Number(surplusCacheStr);
|
||||
const planStatus = await getTeamPlanStatus({ teamId });
|
||||
return {
|
||||
totalPoints,
|
||||
surplusPoints,
|
||||
usedPoints: totalPoints - surplusPoints
|
||||
totalPoints: planStatus.totalPoints,
|
||||
surplusPoints: planStatus.totalPoints - planStatus.usedPoints,
|
||||
usedPoints: planStatus.usedPoints
|
||||
};
|
||||
}
|
||||
},
|
||||
incrTeamPointsCache: async ({ teamId, value }: { teamId: string; value: number }) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
await incrValueToCache(surplusCacheKey, value);
|
||||
},
|
||||
updateTeamPointsCache: async ({
|
||||
teamId,
|
||||
totalPoints,
|
||||
surplusPoints
|
||||
}: {
|
||||
teamId: string;
|
||||
totalPoints: number;
|
||||
surplusPoints: number;
|
||||
}) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
const totalCacheKey = `${CacheKeyEnum.team_point_total}:${teamId}`;
|
||||
|
||||
const planStatus = await getTeamPlanStatus({ teamId });
|
||||
return {
|
||||
totalPoints: planStatus.totalPoints,
|
||||
surplusPoints: planStatus.totalPoints - planStatus.usedPoints,
|
||||
usedPoints: planStatus.usedPoints
|
||||
};
|
||||
await Promise.all([
|
||||
setRedisCache(surplusCacheKey, surplusPoints, CacheKeyEnumTime.team_point_surplus),
|
||||
setRedisCache(totalCacheKey, totalPoints, CacheKeyEnumTime.team_point_total)
|
||||
]);
|
||||
},
|
||||
clearTeamPointsCache: async (teamId: string) => {
|
||||
const surplusCacheKey = `${CacheKeyEnum.team_point_surplus}:${teamId}`;
|
||||
const totalCacheKey = `${CacheKeyEnum.team_point_total}:${teamId}`;
|
||||
|
||||
await Promise.all([delRedisCache(surplusCacheKey), delRedisCache(totalCacheKey)]);
|
||||
}
|
||||
};
|
||||
export const teamQPM = {
|
||||
getTeamQPMLimit: async (teamId: string): Promise<number | null> => {
|
||||
// 1. 尝试从缓存中获取
|
||||
const cacheKey = `${CacheKeyEnum.team_qpm_limit}:${teamId}`;
|
||||
const cached = await getRedisCache(cacheKey);
|
||||
|
||||
if (cached) {
|
||||
return Number(cached);
|
||||
}
|
||||
|
||||
// 2. Computed
|
||||
const teamPlanStatus = await getTeamPlanStatus({ teamId });
|
||||
const limit =
|
||||
teamPlanStatus[SubTypeEnum.standard]?.requestsPerMinute ??
|
||||
teamPlanStatus.standardConstants?.requestsPerMinute;
|
||||
|
||||
if (!limit) {
|
||||
if (process.env.CHAT_MAX_QPM) return Number(process.env.CHAT_MAX_QPM);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. Set cache
|
||||
await teamQPM.setCachedTeamQPMLimit(teamId, limit);
|
||||
|
||||
return limit;
|
||||
},
|
||||
setCachedTeamQPMLimit: async (teamId: string, limit: number): Promise<void> => {
|
||||
const cacheKey = `${CacheKeyEnum.team_qpm_limit}:${teamId}`;
|
||||
await setRedisCache(cacheKey, limit.toString(), CacheKeyEnumTime.team_qpm_limit);
|
||||
},
|
||||
clearTeamQPMLimitCache: async (teamId: string): Promise<void> => {
|
||||
const cacheKey = `${CacheKeyEnum.team_qpm_limit}:${teamId}`;
|
||||
await delRedisCache(cacheKey);
|
||||
}
|
||||
};
|
||||
|
||||
// controler
|
||||
export const clearTeamPlanCache = async (teamId: string) => {
|
||||
await teamPoint.clearTeamPointsCache(teamId);
|
||||
await teamQPM.clearTeamQPMLimitCache(teamId);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user