From b3cf23ebd8f555b4b2da1cea3027097323a4e8a4 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 16 Oct 2024 10:16:09 +0200 Subject: [PATCH] Optimized Bookshelf plugin `sanitize.permittedOptions` - concat is too heavy of a function to call on the hotpath, so we can just replace it with a native spread, which is much faster - this cuts ~1.5% from boot time for sites with a lot of posts --- .../core/server/models/base/plugins/sanitize.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ghost/core/core/server/models/base/plugins/sanitize.js b/ghost/core/core/server/models/base/plugins/sanitize.js index 87e9e73575..d307811e9f 100644 --- a/ghost/core/core/server/models/base/plugins/sanitize.js +++ b/ghost/core/core/server/models/base/plugins/sanitize.js @@ -35,21 +35,21 @@ module.exports = function (Bookshelf) { switch (methodName) { case 'toJSON': - return baseOptions.concat('shallow', 'columns', 'previous'); + return [...baseOptions, 'shallow', 'columns', 'previous']; case 'destroy': - return baseOptions.concat(extraOptions, ['id', 'destroyBy', 'require']); + return [...baseOptions, ...extraOptions, 'id', 'destroyBy', 'require']; case 'add': - return baseOptions.concat(extraOptions, ['autoRefresh']); + return [...baseOptions, ...extraOptions, 'autoRefresh']; case 'edit': - return baseOptions.concat(extraOptions, ['id', 'require', 'autoRefresh']); + return [...baseOptions, ...extraOptions, 'id', 'require', 'autoRefresh']; case 'findOne': - return baseOptions.concat(extraOptions, ['columns', 'require', 'mongoTransformer']); + return [...baseOptions, ...extraOptions, 'columns', 'require', 'mongoTransformer']; case 'findAll': - return baseOptions.concat(extraOptions, ['filter', 'columns', 'mongoTransformer']); + return [...baseOptions, ...extraOptions, 'filter', 'columns', 'mongoTransformer']; case 'findPage': - return baseOptions.concat(extraOptions, ['filter', 'order', 'autoOrder', 'page', 'limit', 'columns', 'mongoTransformer']); + return [...baseOptions, ...extraOptions, 'filter', 'order', 'autoOrder', 'page', 'limit', 'columns', 'mongoTransformer']; default: - return baseOptions.concat(extraOptions); + return [...baseOptions, ...extraOptions]; } },