diff --git a/packages/backend-core/src/events/identification.ts b/packages/backend-core/src/events/identification.ts index 9534fb293d..c85eb16a77 100644 --- a/packages/backend-core/src/events/identification.ts +++ b/packages/backend-core/src/events/identification.ts @@ -65,6 +65,7 @@ const getCurrentIdentity = async (): Promise => { hosting, installationId, tenantId, + realTenantId: context.getTenantId(), environment, } } else if (identityType === IdentityType.USER) { diff --git a/packages/backend-core/src/events/processors/async/DocumentUpdateProcessor.ts b/packages/backend-core/src/events/processors/async/DocumentUpdateProcessor.ts index d64ac1d41d..54304ee21b 100644 --- a/packages/backend-core/src/events/processors/async/DocumentUpdateProcessor.ts +++ b/packages/backend-core/src/events/processors/async/DocumentUpdateProcessor.ts @@ -20,7 +20,7 @@ export default class DocumentUpdateProcessor implements EventProcessor { properties: any, timestamp?: string | number ) { - const tenantId = identity.tenantId + const tenantId = identity.realTenantId const docId = getDocumentId(event, properties) if (!tenantId || !docId) { return diff --git a/packages/server/src/events/docUpdates/processors.ts b/packages/server/src/events/docUpdates/processors.ts index 8f3738f0dc..53036970e0 100644 --- a/packages/server/src/events/docUpdates/processors.ts +++ b/packages/server/src/events/docUpdates/processors.ts @@ -2,8 +2,13 @@ import userGroupProcessor from "./syncUsers" import { docUpdates } from "@budibase/backend-core" export type UpdateCallback = (docId: string) => void +let started = false export function init(updateCb?: UpdateCallback) { + if (started) { + return + } const processors = [userGroupProcessor(updateCb)] docUpdates.init(processors) + started = true } diff --git a/packages/server/src/sdk/app/applications/tests/sync.spec.ts b/packages/server/src/sdk/app/applications/tests/sync.spec.ts index 3b412a7fa7..8609e59a2f 100644 --- a/packages/server/src/sdk/app/applications/tests/sync.spec.ts +++ b/packages/server/src/sdk/app/applications/tests/sync.spec.ts @@ -20,6 +20,8 @@ function updateCb(docId: string) { } } +init(updateCb) + function waitForUpdate(opts: { group?: boolean }) { return new Promise((resolve, reject) => { const timeout = setTimeout(() => { @@ -35,7 +37,6 @@ function waitForUpdate(opts: { group?: boolean }) { beforeAll(async () => { app = await config.init("syncApp") - init(updateCb) }) async function createUser(email: string, roles: UserRoles, builder?: boolean) { diff --git a/packages/types/src/sdk/events/identification.ts b/packages/types/src/sdk/events/identification.ts index 627254882e..7c7a2be8e0 100644 --- a/packages/types/src/sdk/events/identification.ts +++ b/packages/types/src/sdk/events/identification.ts @@ -46,6 +46,8 @@ export interface Identity { environment: string installationId?: string tenantId?: string + // usable - no unique format + realTenantId?: string hostInfo?: HostInfo }