mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-12 04:37:44 +02:00
Reduce getWorkspacesInfo calls (#9408)
* Reduce getWorkspacesInfo calls Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com> * Fix formatting Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com> --------- Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
||||
import config from './config'
|
||||
import { getIntegrations } from './integrations'
|
||||
import { WorkspaceClient } from './workspaceClient'
|
||||
import { cleanUserByEmail } from './kvsUtils'
|
||||
|
||||
export class CalendarController {
|
||||
protected static _instance: CalendarController
|
||||
@@ -66,6 +67,7 @@ export class CalendarController {
|
||||
}
|
||||
|
||||
private async runAll (groups: Map<WorkspaceUuid, Integration[]>): Promise<void> {
|
||||
await cleanUserByEmail()
|
||||
const ids = [...groups.keys()]
|
||||
if (ids.length === 0) return
|
||||
const limiter = new RateLimiter(config.InitLimit)
|
||||
|
||||
@@ -89,3 +89,12 @@ export async function removeUserByEmail (user: User, email: GoogleEmail): Promis
|
||||
await client.setValue<User[]>(key, newCurr)
|
||||
}
|
||||
}
|
||||
|
||||
export async function cleanUserByEmail (): Promise<void> {
|
||||
const client = getKvsClient()
|
||||
const keys = await client.listKeys<User>(`${CALENDAR_INTEGRATION}:users:`)
|
||||
if (keys == null) return
|
||||
for (const key in keys) {
|
||||
await client.deleteKey(key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
//
|
||||
|
||||
import { AccountClient } from '@hcengineering/account-client'
|
||||
import { isActiveMode, MeasureContext, TxOperations } from '@hcengineering/core'
|
||||
import { MeasureContext, TxOperations } from '@hcengineering/core'
|
||||
import { getClient } from './client'
|
||||
import { getUserByEmail, removeUserByEmail } from './kvsUtils'
|
||||
import { IncomingSyncManager } from './sync'
|
||||
@@ -65,16 +65,7 @@ export class PushHandler {
|
||||
async push (email: GoogleEmail, mode: 'events' | 'calendar', calendarId?: string): Promise<void> {
|
||||
const tokens = await getUserByEmail(email)
|
||||
this.ctx.info('push', { email, mode, calendarId, tokens: tokens.length })
|
||||
const workspaces = [...new Set(tokens.map((p) => p.workspace))]
|
||||
const infos = await this.accountClient.getWorkspacesInfo(workspaces)
|
||||
for (const token of tokens) {
|
||||
const info = infos.find((p) => p.uuid === token.workspace)
|
||||
if (info === undefined) {
|
||||
continue
|
||||
}
|
||||
if (!isActiveMode(info.mode)) {
|
||||
continue
|
||||
}
|
||||
await this.sync(token, mode === 'events' ? calendarId ?? null : null)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user