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 cache = {}
|
||||
const knownKeys = {}
|
||||
|
||||
const getContextKeysFromRuntime = function(scope, store, searchKey, done) {
|
||||
knownKeys[store] = knownKeys[store] || new Set()
|
||||
contextKnownKeys[store] = contextKnownKeys[store] || new Set()
|
||||
if (searchKey.length > 0) {
|
||||
try {
|
||||
RED.utils.normalisePropertyExpression(searchKey)
|
||||
@ -125,22 +133,22 @@
|
||||
}
|
||||
}
|
||||
const url = `context/${scope}/${encodeURIComponent(searchKey)}?store=${store}&keysOnly`
|
||||
if (cache[url]) {
|
||||
// console.log('CACHED', url)
|
||||
if (contextCache[url]) {
|
||||
console.log('CACHED', url)
|
||||
done()
|
||||
} else {
|
||||
// console.log('GET', url)
|
||||
console.log('GET', url)
|
||||
$.getJSON(url, function(data) {
|
||||
// console.log(data)
|
||||
cache[url] = true
|
||||
contextCache[url] = true
|
||||
const result = data[store] || {}
|
||||
const keys = result.keys || []
|
||||
const keyPrefix = searchKey + (searchKey.length > 0 ? '.' : '')
|
||||
keys.forEach(key => {
|
||||
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(key)) {
|
||||
knownKeys[store].add(keyPrefix + key)
|
||||
contextKnownKeys[store].add(keyPrefix + key)
|
||||
} else {
|
||||
knownKeys[store].add(searchKey + "[\""+key.replace(/"/,"\\\"")+"\"]")
|
||||
contextKnownKeys[store].add(searchKey + "[\""+key.replace(/"/,"\\\"")+"\"]")
|
||||
}
|
||||
})
|
||||
done()
|
||||
@ -170,12 +178,12 @@
|
||||
const searchKey = keyParts.join('.')
|
||||
|
||||
getContextKeysFromRuntime(scope, store, searchKey, function() {
|
||||
if (knownKeys[store].has(key) || key.endsWith(']')) {
|
||||
if (contextKnownKeys[store].has(key) || key.endsWith(']')) {
|
||||
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