Bypass couch db when using tenancy middleware
This commit is contained in:
parent
e2bef2a323
commit
716eab5d10
|
@ -71,8 +71,10 @@ exports.doInTenant = (tenantId, task) => {
|
|||
// set the tenant id
|
||||
if (!opts.existing) {
|
||||
cls.setOnContext(ContextKeys.TENANT_ID, tenantId)
|
||||
if (env.USE_COUCH) {
|
||||
exports.setGlobalDB(tenantId)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// invoke the task
|
||||
|
@ -80,7 +82,9 @@ exports.doInTenant = (tenantId, task) => {
|
|||
} finally {
|
||||
const using = cls.getFromContext(ContextKeys.IN_USE)
|
||||
if (!using || using <= 1) {
|
||||
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 => {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue