From dd68fca9686cb83aa4e048a1f55586c57852cbba Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 14 Oct 2024 12:28:45 +0200 Subject: [PATCH] Replaced `lodash.{pick,union}` with native JS - this code is a hotpath for the URL service and has shown to be slow for sites with a lot of posts - this is because of the overhead of lodash - we can just do away with lodash and use native JS, which has a negligible performance cost - this cuts about 5% CPU time during boot of large sites --- ghost/core/core/server/models/base/plugins/sanitize.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ghost/core/core/server/models/base/plugins/sanitize.js b/ghost/core/core/server/models/base/plugins/sanitize.js index 9344623820..87e9e73575 100644 --- a/ghost/core/core/server/models/base/plugins/sanitize.js +++ b/ghost/core/core/server/models/base/plugins/sanitize.js @@ -164,11 +164,10 @@ module.exports = function (Bookshelf) { let options = _.cloneDeep(unfilteredOptions); const extraAllowedProperties = filterConfig.extraAllowedProperties || []; - let permittedOptions; - - permittedOptions = this.permittedOptions(methodName, options); - permittedOptions = _.union(permittedOptions, extraAllowedProperties); - options = _.pick(options, permittedOptions); + const permittedOptions = [...new Set([...this.permittedOptions(methodName, options), ...extraAllowedProperties])]; + options = Object.fromEntries( + Object.entries(options).filter(([key]) => permittedOptions.includes(key)) + ); if (this.defaultRelations) { options = this.defaultRelations(methodName, options);