Bulk update improvements (#1428)

This commit is contained in:
Joshua Hull
2021-07-12 07:04:29 -07:00
committed by GitHub
parent 9bf3fdf8f1
commit f2d8cf7d34
3 changed files with 107 additions and 0 deletions

2
lib/Helpers.d.ts vendored
View File

@ -36,6 +36,7 @@ export interface ScrollSearchResponse<TDocument = unknown, TResponse = Record<st
export interface BulkHelper<T> extends Promise<T> {
abort: () => BulkHelper<T>
readonly stats: BulkStats
}
export interface BulkStats {
@ -43,6 +44,7 @@ export interface BulkStats {
failed: number
retry: number
successful: number
noop: number
time: number
bytes: number
aborted: boolean

View File

@ -456,6 +456,7 @@ class Helpers {
failed: 0,
retry: 0,
successful: 0,
noop: 0,
time: 0,
bytes: 0,
aborted: false
@ -463,6 +464,9 @@ class Helpers {
const p = iterate()
const helper = {
get stats () {
return stats
},
then (onFulfilled, onRejected) {
return p.then(onFulfilled, onRejected)
},
@ -692,6 +696,11 @@ class Helpers {
if (err) return callback(err, null)
if (body.errors === false) {
stats.successful += body.items.length
for (const item of body.items) {
if (item.update && item.update.result === 'noop') {
stats.noop++
}
}
return callback(null, [])
}
const retry = []