1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00

Bypass couch db when using tenancy middleware

This commit is contained in:
Rory Powell 2022-04-26 17:13:45 +01:00
parent e2bef2a323
commit 716eab5d10
2 changed files with 16 additions and 2 deletions

View file

@ -71,7 +71,9 @@ exports.doInTenant = (tenantId, task) => {
// set the tenant id
if (!opts.existing) {
cls.setOnContext(ContextKeys.TENANT_ID, tenantId)
exports.setGlobalDB(tenantId)
if (env.USE_COUCH) {
exports.setGlobalDB(tenantId)
}
}
try {
@ -80,7 +82,9 @@ exports.doInTenant = (tenantId, task) => {
} finally {
const using = cls.getFromContext(ContextKeys.IN_USE)
if (!using || using <= 1) {
await closeDB(exports.getGlobalDB())
if (env.USE_COUCH) {
await closeDB(exports.getGlobalDB())
}
// clear from context now that database is closed/task is finished
cls.setOnContext(ContextKeys.TENANT_ID, null)
cls.setOnContext(ContextKeys.GLOBAL_DB, null)
@ -167,6 +171,7 @@ exports.doInAppContext = (appId, task) => {
exports.updateTenantId = tenantId => {
cls.setOnContext(ContextKeys.TENANT_ID, tenantId)
exports.setGlobalDB(tenantId)
}
exports.updateAppId = async appId => {

View file

@ -30,9 +30,18 @@ module.exports = {
COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
PLATFORM_URL: process.env.PLATFORM_URL,
TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS,
USE_COUCH: process.env.USE_COUCH || true,
isTest,
_set(key, value) {
process.env[key] = value
module.exports[key] = value
},
}
// clean up any environment variable edge cases
for (let [key, value] of Object.entries(module.exports)) {
// handle the edge case of "0" to disable an environment variable
if (value === "0") {
module.exports[key] = 0
}
}