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
This commit is contained in:
Daniel Lockyer 2024-10-16 10:16:09 +02:00 committed by Daniel Lockyer
parent d689484324
commit b3cf23ebd8

View File

@ -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];
}
},