Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use consistent $select in all methods, optimize select function #384

Copy link
Copy link
@DaddyWarbucks

Description

@DaddyWarbucks
Issue body actions

The _find method uses Sequelize's attributes option to select properties.

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);
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.