feat: updated rate policy

This commit is contained in:
Yanlong Wang 2024-08-02 19:39:51 +08:00
parent 0a2c0932fd
commit cda0f371e1
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
3 changed files with 24 additions and 10 deletions

View File

@ -644,10 +644,17 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`;
throw new InsufficientBalanceError(`Account balance not enough to run this query, please recharge.`);
}
const rateLimitPolicy = auth.getRateLimits(rpcReflect.name.toUpperCase()) || [RateLimitDesc.from({
occurrence: 200,
periodSeconds: 60
})];
const rateLimitPolicy = auth.getRateLimits(rpcReflect.name.toUpperCase()) || [
parseInt(user.metadata?.speed_level) >= 2 ?
RateLimitDesc.from({
occurrence: 1000,
periodSeconds: 60
}) :
RateLimitDesc.from({
occurrence: 200,
periodSeconds: 60
})
];
const apiRoll = await this.rateLimitControl.simpleRPCUidBasedLimit(
rpcReflect, uid, [rpcReflect.name.toUpperCase()],

View File

@ -109,10 +109,17 @@ export class SearcherHost extends RPCHost {
throw new InsufficientBalanceError(`Account balance not enough to run this query, please recharge.`);
}
const rateLimitPolicy = auth.getRateLimits(rpcReflect.name.toUpperCase()) || [RateLimitDesc.from({
occurrence: 40,
periodSeconds: 60
})];
const rateLimitPolicy = auth.getRateLimits(rpcReflect.name.toUpperCase()) || [
parseInt(user.metadata?.speed_level) >= 2 ?
RateLimitDesc.from({
occurrence: 200,
periodSeconds: 60
}) :
RateLimitDesc.from({
occurrence: 40,
periodSeconds: 60
})
];
const apiRoll = await this.rateLimitControl.simpleRPCUidBasedLimit(
rpcReflect, uid, [rpcReflect.name.toUpperCase()],
@ -334,7 +341,7 @@ export class SearcherHost extends RPCHost {
r.description = upstreamSearchResult.description;
return r;
}).catch((err)=> {
}).catch((err) => {
this.logger.error(`Failed to format snapshot for ${urls[i].href}`, { err: marshalErrorLike(err) });
return {

@ -1 +1 @@
Subproject commit a26b633136a2651f01dcf02b47efc35b2401d807
Subproject commit fe71cc2433f60ada86622f1670a752da40806e4d