Feat: Plan cache (#5052)

* add cache for team member,app,dataset (#5007)

* add cache for team member,app,dataset

* update for hook

* update redis

* update

* perf: cache code

* fix: i18n

---------

Co-authored-by: gggaaallleee <91131304+gggaaallleee@users.noreply.github.com>
This commit is contained in:
Archer
2025-06-17 18:14:38 +08:00
committed by GitHub
parent af3221fa47
commit 41f73e6f7b
6 changed files with 104 additions and 17 deletions

View File

@@ -6,7 +6,14 @@ import { type DelDatasetVectorCtrlProps, type InsertVectorProps } from './contro
import { type EmbeddingModelItemType } from '@fastgpt/global/core/ai/model.d';
import { MILVUS_ADDRESS, PG_ADDRESS, OCEANBASE_ADDRESS } from './constants';
import { MilvusCtrl } from './milvus';
import { setRedisCache, getRedisCache, delRedisCache, CacheKeyEnum } from '../redis/cache';
import {
setRedisCache,
getRedisCache,
delRedisCache,
incrValueToCache,
CacheKeyEnum,
CacheKeyEnumTime
} from '../redis/cache';
import { throttle } from 'lodash';
import { retryFn } from '@fastgpt/global/common/system/utils';
@@ -23,6 +30,7 @@ const onDelCache = throttle((teamId: string) => delRedisCache(getChcheKey(teamId
leading: true,
trailing: true
});
const onIncrCache = (teamId: string) => incrValueToCache(getChcheKey(teamId), 1);
const Vector = getVectorObj();
@@ -40,7 +48,7 @@ export const getVectorCountByTeamId = async (teamId: string) => {
const count = await Vector.getVectorCountByTeamId(teamId);
await setRedisCache(key, count, 30 * 60);
await setRedisCache(key, count, CacheKeyEnumTime.team_vector_count);
return count;
};
@@ -67,7 +75,7 @@ export const insertDatasetDataVector = async ({
vector: vectors[0]
});
onDelCache(props.teamId);
onIncrCache(props.teamId);
return {
tokens,