Skip to content

Commit 36e44ce

Browse files
authored
fix: rely on lazy tenant initialisation instead of bulk initialisation after startup (#138)
1 parent 12a1258 commit 36e44ce

4 files changed

Lines changed: 7 additions & 31 deletions

File tree

package-lock.json

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"fs-xattr": "^0.3.1",
4040
"jsonwebtoken": "^8.5.1",
4141
"knex": "^1.0.3",
42-
"p-limit": "^3.1.0",
4342
"pg": "^8.7.3",
4443
"pg-listen": "^1.7.0",
4544
"pino": "^7.8.0",

src/server.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import build from './app'
66
import buildAdmin from './admin-app'
77
import { getConfig } from './utils/config'
88
import { runMultitenantMigrations, runMigrations } from './utils/migrate'
9-
import { cacheTenantConfigsFromDbAndRunMigrations, listenForTenantUpdate } from './utils/tenant'
9+
import { listenForTenantUpdate } from './utils/tenant'
1010

1111
const logger = pino({
1212
formatters: {
@@ -51,8 +51,4 @@ const exposeDocs = true
5151
}
5252
console.log(`Server listening at ${address}`)
5353
})
54-
55-
if (isMultitenant) {
56-
await cacheTenantConfigsFromDbAndRunMigrations()
57-
}
5854
})()

src/utils/tenant.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pLimit from 'p-limit'
21
import createSubscriber from 'pg-listen'
32
import { getConfig } from './config'
43
import { decrypt } from './crypto'
@@ -48,28 +47,6 @@ export function deleteTenantConfig(tenantId: string): void {
4847
tenantConfigCache.delete(tenantId)
4948
}
5049

51-
export async function cacheTenantConfigsFromDbAndRunMigrations(): Promise<void> {
52-
const tenants = await knex('tenants').select()
53-
const limit = pLimit(100)
54-
await Promise.all(
55-
tenants.map(({ id, anon_key, database_url, file_size_limit, jwt_secret, service_key }) =>
56-
limit(() =>
57-
cacheTenantConfigAndRunMigrations(
58-
id,
59-
{
60-
anonKey: decrypt(anon_key),
61-
databaseUrl: decrypt(database_url),
62-
fileSizeLimit: Number(file_size_limit),
63-
jwtSecret: decrypt(jwt_secret),
64-
serviceKey: decrypt(service_key),
65-
},
66-
true
67-
)
68-
)
69-
)
70-
)
71-
}
72-
7350
async function getTenantConfig(tenantId: string): Promise<TenantConfig> {
7451
if (tenantConfigCache.has(tenantId)) {
7552
return tenantConfigCache.get(tenantId) as TenantConfig

0 commit comments

Comments
 (0)