mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-26 06:12:23 +02:00
UBERF-9099: Rate limits (#7629)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import core, {
|
||||
RateLimiter,
|
||||
Ref,
|
||||
systemAccountEmail,
|
||||
TimeRateLimiter,
|
||||
TxOperations
|
||||
} from '@hcengineering/core'
|
||||
import github, { GithubAuthentication, makeQuery, type GithubIntegration } from '@hcengineering/github'
|
||||
@@ -73,6 +74,8 @@ export class PlatformWorker {
|
||||
|
||||
userManager!: UserManager
|
||||
|
||||
rateLimits = new Map<string, TimeRateLimiter>()
|
||||
|
||||
private constructor (
|
||||
readonly ctx: MeasureContext,
|
||||
readonly app: App,
|
||||
@@ -83,6 +86,15 @@ export class PlatformWorker {
|
||||
registerLoaders()
|
||||
}
|
||||
|
||||
getRateLimiter (endpoint: string): TimeRateLimiter {
|
||||
let limiter = this.rateLimits.get(endpoint)
|
||||
if (limiter === undefined) {
|
||||
limiter = new TimeRateLimiter(config.RateLimit)
|
||||
this.rateLimits.set(endpoint, limiter)
|
||||
}
|
||||
return limiter
|
||||
}
|
||||
|
||||
public async initStorage (): Promise<void> {
|
||||
this.mongoRef = getMongoClient(config.MongoURL)
|
||||
const mongoClient = await this.mongoRef.getClient()
|
||||
@@ -230,7 +242,7 @@ export class PlatformWorker {
|
||||
} else {
|
||||
let client: Client | undefined
|
||||
try {
|
||||
client = await createPlatformClient(oldWorkspace, 30000)
|
||||
;({ client } = await createPlatformClient(oldWorkspace, 30000))
|
||||
await this.removeInstallationFromWorkspace(oldWorker, installationId)
|
||||
await client.close()
|
||||
} catch (err: any) {
|
||||
@@ -386,7 +398,7 @@ export class PlatformWorker {
|
||||
platformClient = this.clients.get(payload.workspace)?.client
|
||||
if (platformClient === undefined) {
|
||||
shouldClose = true
|
||||
platformClient = await createPlatformClient(payload.workspace, 30000)
|
||||
;({ client: platformClient } = await createPlatformClient(payload.workspace, 30000))
|
||||
}
|
||||
const client = new TxOperations(platformClient, payload.accountId)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user