Merge pull request #12636 from Budibase/cache-get-helpers-list

Cache the helpers list for executing JS.
This commit is contained in:
Sam Rose 2024-01-02 16:02:57 +00:00 committed by GitHub
commit de3302600f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -1,19 +1,26 @@
const externalHandlebars = require("./external") const externalHandlebars = require("./external")
const helperList = require("@budibase/handlebars-helpers") const helperList = require("@budibase/handlebars-helpers")
let helpers = undefined
module.exports.getHelperList = () => { module.exports.getHelperList = () => {
if (helpers) {
return helpers
}
helpers = {}
let constructed = [] let constructed = []
for (let collection of externalHandlebars.externalCollections) { for (let collection of externalHandlebars.externalCollections) {
constructed.push(helperList[collection]()) constructed.push(helperList[collection]())
} }
const fullMap = {}
for (let collection of constructed) { for (let collection of constructed) {
for (let [key, func] of Object.entries(collection)) { for (let [key, func] of Object.entries(collection)) {
fullMap[key] = func helpers[key] = func
} }
} }
for (let key of Object.keys(externalHandlebars.addedHelpers)) { for (let key of Object.keys(externalHandlebars.addedHelpers)) {
fullMap[key] = externalHandlebars.addedHelpers[key] helpers[key] = externalHandlebars.addedHelpers[key]
} }
return fullMap Object.freeze(helpers)
return helpers
} }