mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Clear context cache when closing edit dialog
This commit is contained in:
parent
ea4c0cdbee
commit
a77f8cc3e9
@ -109,12 +109,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let contextKnownKeys = {}
|
||||||
|
let contextCache = {}
|
||||||
|
if (RED.events) {
|
||||||
|
RED.events.on("editor:close", function () {
|
||||||
|
contextCache = {}
|
||||||
|
contextKnownKeys = {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const contextAutoComplete = function(options) {
|
const contextAutoComplete = function(options) {
|
||||||
const cache = {}
|
|
||||||
const knownKeys = {}
|
|
||||||
|
|
||||||
const getContextKeysFromRuntime = function(scope, store, searchKey, done) {
|
const getContextKeysFromRuntime = function(scope, store, searchKey, done) {
|
||||||
knownKeys[store] = knownKeys[store] || new Set()
|
contextKnownKeys[store] = contextKnownKeys[store] || new Set()
|
||||||
if (searchKey.length > 0) {
|
if (searchKey.length > 0) {
|
||||||
try {
|
try {
|
||||||
RED.utils.normalisePropertyExpression(searchKey)
|
RED.utils.normalisePropertyExpression(searchKey)
|
||||||
@ -125,22 +133,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const url = `context/${scope}/${encodeURIComponent(searchKey)}?store=${store}&keysOnly`
|
const url = `context/${scope}/${encodeURIComponent(searchKey)}?store=${store}&keysOnly`
|
||||||
if (cache[url]) {
|
if (contextCache[url]) {
|
||||||
// console.log('CACHED', url)
|
console.log('CACHED', url)
|
||||||
done()
|
done()
|
||||||
} else {
|
} else {
|
||||||
// console.log('GET', url)
|
console.log('GET', url)
|
||||||
$.getJSON(url, function(data) {
|
$.getJSON(url, function(data) {
|
||||||
// console.log(data)
|
// console.log(data)
|
||||||
cache[url] = true
|
contextCache[url] = true
|
||||||
const result = data[store] || {}
|
const result = data[store] || {}
|
||||||
const keys = result.keys || []
|
const keys = result.keys || []
|
||||||
const keyPrefix = searchKey + (searchKey.length > 0 ? '.' : '')
|
const keyPrefix = searchKey + (searchKey.length > 0 ? '.' : '')
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(key)) {
|
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(key)) {
|
||||||
knownKeys[store].add(keyPrefix + key)
|
contextKnownKeys[store].add(keyPrefix + key)
|
||||||
} else {
|
} else {
|
||||||
knownKeys[store].add(searchKey + "[\""+key.replace(/"/,"\\\"")+"\"]")
|
contextKnownKeys[store].add(searchKey + "[\""+key.replace(/"/,"\\\"")+"\"]")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
done()
|
done()
|
||||||
@ -170,12 +178,12 @@
|
|||||||
const searchKey = keyParts.join('.')
|
const searchKey = keyParts.join('.')
|
||||||
|
|
||||||
getContextKeysFromRuntime(scope, store, searchKey, function() {
|
getContextKeysFromRuntime(scope, store, searchKey, function() {
|
||||||
if (knownKeys[store].has(key) || key.endsWith(']')) {
|
if (contextKnownKeys[store].has(key) || key.endsWith(']')) {
|
||||||
getContextKeysFromRuntime(scope, store, key, function() {
|
getContextKeysFromRuntime(scope, store, key, function() {
|
||||||
done(knownKeys[store])
|
done(contextKnownKeys[store])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
done(knownKeys[store])
|
done(contextKnownKeys[store])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user