feat(databases): Add support for fast bulk operations#2945
feat(databases): Add support for fast bulk operations#2945
Conversation
✅ Deploy Preview for feathers-dove ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
| if (Array.isArray(data)) { | ||
| return Promise.all(data.map((current) => this._create(current, params))) | ||
| } | ||
| const payload = Array.isArray(_data) ? _data : [_data] |
There was a problem hiding this comment.
To skip the extra processing for large arrays, we can add another check for params.bulk before running .map:
const payload = Array.isArray(_data) ? _data : [_data]
const results = (params.bulk ? [] : payload).map((value) => {
const id = (value as any)[this.id] || this._uId++
const current = _.extend({}, value, { [this.id]: id })
return _select((this.store[id] = current), params, this.id)
})
return params.bulk ? [] : Array.isArray(_data) ? results : results[0]There was a problem hiding this comment.
It looks like we also need to address the scenario where we create a single record and also pass params.bulk:
const david = await service.create(
{
name: 'David',
age: 3,
created: true
},
{ bulk: true }
)We don't want to return an empty array for the above scenario since that breaks the request-to-response plurality mapping of the service interface. So we probably ought to throw an error:
if (!Array.isArray(_data) && params.bulk) {
throw new BadRequest()
}| * @returns Wether or not multiple updates are allowed. | ||
| */ | ||
| allowsMulti(method: string, params: ServiceParams = {} as ServiceParams) { | ||
| if (params.bulk) { |
There was a problem hiding this comment.
Maybe we can update allowMulti to accept context.id and have a centralized place to throw an error whenever params.bulk === true and
- For create:
datais an object - For patch and remove:
context.idis null
|
Lets also solve the merge conflicts |
|
Any ETA on this? Running to issues where this would help. |
|
This is more than a year old, can I make the requested changes? |
This pull request adds the ability to the built in database adapters to perform fast bulk operations for
create,patchandremoveby passingparams.bulk = true. Bulk operations will use the fastest database call available and - when successful - always return no data (an empty array) and not send real time events.Closes feathersjs-ecosystem/feathers-mongodb#219