Skip to content

Commit 3d33954

Browse files
authored
Reduce getWorkspacesInfo calls (#9408)
* Reduce getWorkspacesInfo calls Signed-off-by: Denis Bykhov <[email protected]> * Fix formatting Signed-off-by: Denis Bykhov <[email protected]> --------- Signed-off-by: Denis Bykhov <[email protected]>
1 parent 5eccbe6 commit 3d33954

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

services/calendar/pod-calendar/src/calendarController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import config from './config'
2626
import { getIntegrations } from './integrations'
2727
import { WorkspaceClient } from './workspaceClient'
28+
import { cleanUserByEmail } from './kvsUtils'
2829

2930
export class CalendarController {
3031
protected static _instance: CalendarController
@@ -66,6 +67,7 @@ export class CalendarController {
6667
}
6768

6869
private async runAll (groups: Map<WorkspaceUuid, Integration[]>): Promise<void> {
70+
await cleanUserByEmail()
6971
const ids = [...groups.keys()]
7072
if (ids.length === 0) return
7173
const limiter = new RateLimiter(config.InitLimit)

services/calendar/pod-calendar/src/kvsUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,12 @@ export async function removeUserByEmail (user: User, email: GoogleEmail): Promis
8989
await client.setValue<User[]>(key, newCurr)
9090
}
9191
}
92+
93+
export async function cleanUserByEmail (): Promise<void> {
94+
const client = getKvsClient()
95+
const keys = await client.listKeys<User>(`${CALENDAR_INTEGRATION}:users:`)
96+
if (keys == null) return
97+
for (const key in keys) {
98+
await client.deleteKey(key)
99+
}
100+
}

services/calendar/pod-calendar/src/pushHandler.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515

1616
import { AccountClient } from '@hcengineering/account-client'
17-
import { isActiveMode, MeasureContext, TxOperations } from '@hcengineering/core'
17+
import { MeasureContext, TxOperations } from '@hcengineering/core'
1818
import { getClient } from './client'
1919
import { getUserByEmail, removeUserByEmail } from './kvsUtils'
2020
import { IncomingSyncManager } from './sync'
@@ -65,16 +65,7 @@ export class PushHandler {
6565
async push (email: GoogleEmail, mode: 'events' | 'calendar', calendarId?: string): Promise<void> {
6666
const tokens = await getUserByEmail(email)
6767
this.ctx.info('push', { email, mode, calendarId, tokens: tokens.length })
68-
const workspaces = [...new Set(tokens.map((p) => p.workspace))]
69-
const infos = await this.accountClient.getWorkspacesInfo(workspaces)
7068
for (const token of tokens) {
71-
const info = infos.find((p) => p.uuid === token.workspace)
72-
if (info === undefined) {
73-
continue
74-
}
75-
if (!isActiveMode(info.mode)) {
76-
continue
77-
}
7869
await this.sync(token, mode === 'events' ? calendarId ?? null : null)
7970
}
8071
}

0 commit comments

Comments
 (0)