@feathers-plus/batch-loader

Reduce requests to backend services by batching calls and caching records.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
85Jun 12, 2021Nov 6, 2017Minified + gzip package size for @feathers-plus/batch-loader in KB

Readme

feathers-plus/batch-loader

Build Status Code Climate Test Coverage Dependency Status Download Status

Reduce requests to backend services by batching calls and caching records.

Installation

npm install @feathers-plus/batch-loader --save

Documentation

Please refer to the batch-loader documentation for more details.

Complete Example

Here's an example of a Feathers server that uses feathers-plus/batch-loader.

const BatchLoader = require('@feathers-plus/batch-loader');
const { getResultsByKey, getUniqueKeys } = BatchLoader;

const usersBatchLoader = new BatchLoader(
  keys => app.service('users').find({ query: { id: { $in: getUniqueKeys(keys) } } })
    .then(result => getResultsByKey(keys, result, user => user.id, '!'))
);

app.service('comments').find()
  .then(comments => Promise.all(comments.map(comment => {
    // Attach user record
    return usersBatchLoader.load(comment.userId)
      .then(user => comment.userRecord = user);
  })))

License

Copyright (c) 2017 John J. Szwaronek

Licensed under the MIT license.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.