perf: index

This commit is contained in:
archer
2023-06-25 15:52:04 +08:00
parent 68eca25df4
commit f56a339ad1
6 changed files with 18 additions and 9 deletions

View File

@@ -60,10 +60,6 @@ function App({ Component, pageProps }: AppProps) {
src={`https://www.recaptcha.net/recaptcha/api.js?render=${googleVerKey}`}
strategy="afterInteractive"
></Script>
<Script
src={`https://www.google.com/recaptcha/api.js?render=${googleVerKey}`}
strategy="afterInteractive"
></Script>
</>
)}
<QueryClientProvider client={queryClient}>

View File

@@ -153,7 +153,8 @@ A2:
sendInform({
type: 'system',
title: 'QA 任务中止',
content: '由于账号余额不足QA 任务中止,重新充值后将会继续。',
content:
'由于账号余额不足,索引生成任务中止,重新充值后将会继续。暂停的任务将在 7 天后被删除。',
userId
});
console.log('余额不足,暂停向量生成任务');

View File

@@ -104,7 +104,8 @@ export async function generateVector(): Promise<any> {
sendInform({
type: 'system',
title: '索引生成任务中止',
content: '由于账号余额不足,索引生成任务中止,重新充值后将会继续。',
content:
'由于账号余额不足,索引生成任务中止,重新充值后将会继续。暂停的任务将在 7 天后被删除。',
userId
});
console.log('余额不足,暂停向量生成任务');

View File

@@ -15,6 +15,10 @@ const TrainingDataSchema = new Schema({
ref: 'kb',
required: true
},
expireAt: {
type: Date,
default: () => new Date()
},
lockTime: {
type: Date,
default: () => new Date('2000/1/1')
@@ -44,5 +48,13 @@ const TrainingDataSchema = new Schema({
}
});
try {
TrainingDataSchema.index({ lockTime: 1 });
TrainingDataSchema.index({ userId: 1 });
TrainingDataSchema.index({ expireAt: 1 }, { expireAfterSeconds: 7 * 24 * 60 });
} catch (error) {
console.log(error);
}
export const TrainingData: MongoModel<TrainingDateType> =
models['trainingData'] || model('trainingData', TrainingDataSchema);

View File

@@ -176,7 +176,7 @@ export const getApiKey = async ({
userId: string;
mustPay?: boolean;
}) => {
const user = await User.findById(userId);
const user = await User.findById(userId, 'openaiKey balance');
if (!user) {
return Promise.reject(ERROR_ENUM.unAuthorization);
}
@@ -207,7 +207,6 @@ export const getApiKey = async ({
// 有自己的key
if (!mustPay && keyMap[model].userOpenAiKey) {
return {
user,
userOpenAiKey: keyMap[model].userOpenAiKey,
systemAuthKey: ''
};
@@ -219,7 +218,6 @@ export const getApiKey = async ({
}
return {
user,
userOpenAiKey: '',
systemAuthKey: keyMap[model].systemAuthKey
};

View File

@@ -70,6 +70,7 @@ export interface TrainingDataSchema {
_id: string;
userId: string;
kbId: string;
expireAt: Date;
lockTime: Date;
mode: `${TrainingModeEnum}`;
prompt: string;