Delete and invalidate linked dynamic variables when a query is deleted
This commit is contained in:
parent
e115a561c2
commit
8210ed7ee4
|
@ -66,7 +66,7 @@ export class OpenAPI2 extends OpenAPISource {
|
|||
getInfo = async (): Promise<ImportInfo> => {
|
||||
const name = this.document.info.title || "Swagger Import"
|
||||
return {
|
||||
name
|
||||
name,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ const { BaseQueryVerbs } = require("../../../constants")
|
|||
const { Thread, ThreadType } = require("../../../threads")
|
||||
const { save: saveDatasource } = require("../datasource")
|
||||
const { RestImporter } = require("./import")
|
||||
const { invalidateDynamicVariables } = require("../../../threads/utils")
|
||||
|
||||
const Runner = new Thread(ThreadType.QUERY, { timeoutMs: 10000 })
|
||||
|
||||
|
@ -166,8 +167,28 @@ exports.executeV2 = async function (ctx) {
|
|||
return execute(ctx, { rowsOnly: false })
|
||||
}
|
||||
|
||||
const removeDynamicVariables = async (db, queryId) => {
|
||||
const query = await db.get(queryId)
|
||||
const datasource = await db.get(query.datasourceId)
|
||||
const dynamicVariables = datasource.config.dynamicVariables
|
||||
|
||||
if (dynamicVariables) {
|
||||
// invalidate the deleted variables
|
||||
const variablesToDelete = dynamicVariables.filter(
|
||||
dv => dv.queryId === queryId
|
||||
)
|
||||
await invalidateDynamicVariables(variablesToDelete)
|
||||
|
||||
// delete dynamic variables from the datasource
|
||||
const newVariables = dynamicVariables.filter(dv => dv.queryId !== queryId)
|
||||
datasource.config.dynamicVariables = newVariables
|
||||
await db.put(datasource)
|
||||
}
|
||||
}
|
||||
|
||||
exports.destroy = async function (ctx) {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
await removeDynamicVariables(db, ctx.params.queryId)
|
||||
await db.remove(ctx.params.queryId, ctx.params.revId)
|
||||
ctx.message = `Query deleted.`
|
||||
ctx.status = 200
|
||||
|
|
|
@ -42,10 +42,11 @@ exports.checkCacheForDynamicVariable = async (queryId, variable) => {
|
|||
}
|
||||
|
||||
exports.invalidateDynamicVariables = async cachedVars => {
|
||||
const cache = await getClient()
|
||||
let promises = []
|
||||
for (let variable of cachedVars) {
|
||||
promises.push(
|
||||
client.delete(makeVariableKey(variable.queryId, variable.name))
|
||||
cache.delete(makeVariableKey(variable.queryId, variable.name))
|
||||
)
|
||||
}
|
||||
await Promise.all(promises)
|
||||
|
|
Loading…
Reference in New Issue