Skip to content

Commit f87e421

Browse files
committed
fix: improve updateMany performance
1 parent 5ae68a9 commit f87e421

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Collection/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
233233
const items = this.getItems(selector)
234234
const modifiedItems: T[] = []
235235
items.forEach((item) => {
236-
const index = this.memory().findIndex(doc => doc === item)
236+
const { index } = this.getItemAndIndex({ id: item.id } as Selector<T>)
237237
if (index === -1) throw new Error('Cannot resolve index for item')
238238
const modifiedItem = modify(item, modifier)
239239
this.memory().splice(index, 1, modifiedItem)
240-
this.rebuildIndexes()
241240
modifiedItems.push(modifiedItem)
242241
})
242+
this.rebuildIndexes()
243243
modifiedItems.forEach((modifiedItem) => {
244244
this.emit('changed', modifiedItem)
245245
})

0 commit comments

Comments
 (0)