2021-12-15 12:25:52 +01:00
|
|
|
const env = require("../environment")
|
|
|
|
const CouchDB = require("../db")
|
|
|
|
const { init } = require("@budibase/auth")
|
2021-12-16 17:58:15 +01:00
|
|
|
const redis = require("@budibase/auth/redis")
|
|
|
|
const { SEPARATOR } = require("@budibase/auth/db")
|
|
|
|
|
|
|
|
let client
|
|
|
|
|
|
|
|
if (!client) {
|
|
|
|
client = await new redis.Client(redis.utils.Databases.QUERY_VARS).init()
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on("exit", async () => {
|
|
|
|
if (client) await client.finish()
|
|
|
|
})
|
2021-12-15 12:25:52 +01:00
|
|
|
|
|
|
|
exports.threadSetup = () => {
|
2021-12-15 13:26:29 +01:00
|
|
|
// don't run this if not threading
|
|
|
|
if (env.isTest() || env.DISABLE_THREADING) {
|
|
|
|
return
|
|
|
|
}
|
2021-12-15 12:25:52 +01:00
|
|
|
// when thread starts, make sure it is recorded
|
|
|
|
env.setInThread()
|
|
|
|
init(CouchDB)
|
|
|
|
}
|
2021-12-16 17:58:15 +01:00
|
|
|
|
|
|
|
function makeVariableKey(queryId, variable) {
|
|
|
|
return `${queryId}${SEPARATOR}${variable}`
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.checkCacheForDynamicVariable = async (queryId, variable) => {
|
|
|
|
await client.get(makeVariableKey(queryId, variable))
|
|
|
|
}
|