mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-11 20:27:43 +02:00
Fix calendar flood (#9405)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -31,7 +31,7 @@ import { Credentials, OAuth2Client } from 'google-auth-library'
|
||||
import { calendar_v3, google } from 'googleapis'
|
||||
import { encode64 } from './base64'
|
||||
import { getClient } from './client'
|
||||
import { addUserByEmail, removeUserByEmail } from './kvsUtils'
|
||||
import { addUserByEmail, removeUserByEmail, setSyncHistory } from './kvsUtils'
|
||||
import { IncomingSyncManager, lock } from './sync'
|
||||
import { CALENDAR_INTEGRATION, GoogleEmail, SCOPES, State, Token, User } from './types'
|
||||
import { getGoogleClient, getWorkspaceToken, removeIntegrationSecret } from './utils'
|
||||
@@ -140,6 +140,7 @@ export class AuthController {
|
||||
const authRes = await this.authorize(code)
|
||||
await this.setWorkspaceIntegration(authRes)
|
||||
if (authRes.success) {
|
||||
await setSyncHistory(this.user.workspace, Date.now())
|
||||
void IncomingSyncManager.initSync(
|
||||
this.ctx,
|
||||
this.accountClient,
|
||||
|
||||
@@ -92,7 +92,6 @@ export class WorkspaceClient {
|
||||
await addUserByEmail(parsedToken, token.key as GoogleEmail)
|
||||
await this.createCalendarClient(parsedToken)
|
||||
}
|
||||
await this.getNewEvents()
|
||||
const limiter = new RateLimiter(config.InitLimit)
|
||||
for (const token of tokens) {
|
||||
await limiter.add(async () => {
|
||||
@@ -100,6 +99,8 @@ export class WorkspaceClient {
|
||||
await IncomingSyncManager.sync(this.ctx, this.accountClient, parsedToken, parsedToken.email)
|
||||
})
|
||||
}
|
||||
await limiter.waitProcessing()
|
||||
await this.getNewEvents()
|
||||
}
|
||||
|
||||
private async createCalendarClient (user: Token): Promise<CalendarClient | undefined> {
|
||||
@@ -135,6 +136,10 @@ export class WorkspaceClient {
|
||||
|
||||
private async getNewEvents (): Promise<void> {
|
||||
const lastSync = await getSyncHistory(this.workspace)
|
||||
if (lastSync === undefined) {
|
||||
await setSyncHistory(this.workspace, Date.now())
|
||||
return
|
||||
}
|
||||
this.lastSync = lastSync ?? 0
|
||||
const baseQuery = {
|
||||
calendar: { $in: Array.from(this.calendarsById.keys()) }
|
||||
|
||||
Reference in New Issue
Block a user