mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
4.8.12 test fix (#2988)
* perf: qps limit * perf: http response data * perf: json path check * fix: ts * loop support reference parent variable
This commit is contained in:
@@ -17,7 +17,7 @@ const FrequencyLimitSchema = new Schema({
|
||||
});
|
||||
|
||||
try {
|
||||
FrequencyLimitSchema.index({ eventId: 1 }, { unique: true });
|
||||
FrequencyLimitSchema.index({ eventId: 1, expiredTime: 1 });
|
||||
FrequencyLimitSchema.index({ expiredTime: 1 }, { expireAfterSeconds: 0 });
|
||||
} catch (error) {}
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import { AuthFrequencyLimitProps } from '@fastgpt/global/common/frequenctLimit/type';
|
||||
import { MongoFrequencyLimit } from './schema';
|
||||
import { readFromSecondary } from '../../mongo/utils';
|
||||
|
||||
export const authFrequencyLimit = async ({
|
||||
eventId,
|
||||
@@ -11,22 +10,24 @@ export const authFrequencyLimit = async ({
|
||||
// 对应 eventId 的 account+1, 不存在的话,则创建一个
|
||||
const result = await MongoFrequencyLimit.findOneAndUpdate(
|
||||
{
|
||||
eventId
|
||||
eventId,
|
||||
expiredTime: { $gte: new Date() }
|
||||
},
|
||||
{
|
||||
$inc: { amount: 1 },
|
||||
// If not exist, set the expiredTime
|
||||
$setOnInsert: { expiredTime }
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
...readFromSecondary
|
||||
new: true
|
||||
}
|
||||
);
|
||||
|
||||
).lean();
|
||||
// 因为始终会返回+1的结果,所以这里不能直接等,需要多一个。
|
||||
if (result.amount > maxAmount) {
|
||||
return Promise.reject(result);
|
||||
}
|
||||
} catch (error) {}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user