-
Notifications
You must be signed in to change notification settings - Fork 75
Description
The _find method uses Sequelize's attributes option to select properties.
feathers-sequelize/lib/index.js
Line 135 in db4b5ff
| if (filters.$select) { |
But it does not use the
select function from adapters-commons on its results. All other methods do use this select function but not the attributes option. Is there a reason _get does not also use the attributes option? I don't see why it wouldn't work. The _find method should also use the select function.
If we use attributes in _get, then that should cover most other methods as they call _findOrGet under the hood. But _create uses Model.create and Model.bulkCreate and does not then call _findOrGet. I am curious if these Sequelize methods also support attributes.
If using attributes on all methods, is the select function even needed at that point? Even if not, it should likely be left in place for consistency across all adapter types. On the other hand, should we be using attributes at all and solely relying on the select function?
I am making an assumption that using atrributes on all methods would give us a performance boost. But, it generally makes sense that only selecting the columns we want returned at the SQL level would be better.
Furthermore, we should only use select function when there is a $select filter. Otherwise we are wasting loops. Even though select just returns result => result when there is no $select, with some simple conditionals we could check filters.$select then call select if needed. This is arguably a micro optimization when considering small results, but could make a difference with larger results. See: https://github.com/feathersjs/feathers/blob/dove/packages/adapter-commons/src/index.ts
For example,
return Model.findAll(q)
.then((results) => {
if (!filters.$select) {
return results;
}
return select(params, this.id)(results);
})
.catch(utils.errorHandler);