0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

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
This commit is contained in:
Daniel Lockyer 2024-10-14 12:28:45 +02:00 committed by Daniel Lockyer
parent 30220aa6ef
commit dd68fca968

View file

@ -164,11 +164,10 @@ module.exports = function (Bookshelf) {
let options = _.cloneDeep(unfilteredOptions); let options = _.cloneDeep(unfilteredOptions);
const extraAllowedProperties = filterConfig.extraAllowedProperties || []; const extraAllowedProperties = filterConfig.extraAllowedProperties || [];
let permittedOptions; const permittedOptions = [...new Set([...this.permittedOptions(methodName, options), ...extraAllowedProperties])];
options = Object.fromEntries(
permittedOptions = this.permittedOptions(methodName, options); Object.entries(options).filter(([key]) => permittedOptions.includes(key))
permittedOptions = _.union(permittedOptions, extraAllowedProperties); );
options = _.pick(options, permittedOptions);
if (this.defaultRelations) { if (this.defaultRelations) {
options = this.defaultRelations(methodName, options); options = this.defaultRelations(methodName, options);