Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

[perf] optimise key index #48

Merged
merged 2 commits into from
Dec 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/KeyValueIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ class KeyValueIndex {
}

updateIndex(oplog) {
oplog.values
.slice()
.reverse()
.reduce((handled, item) => {
if(!handled.includes(item.payload.key)) {
handled.push(item.payload.key)
if(item.payload.op === 'PUT') {
this._index[item.payload.key] = item.payload.value
} else if(item.payload.op === 'DEL') {
delete this._index[item.payload.key]
}
}
return handled
}, [])
const values = oplog.values

const handled = {}
for (let i = values.length - 1; i >= 0; i--) {
const item = values[i]
if (handled[item.payload.key]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with 1.0 i want to make sure payload is always defined but this is fine for now, all store indexes are are like this atm.

return
}
handled[item.payload.key] = true
if (item.payload.op === 'PUT') {
this._index[item.payload.key] = item.payload.value
return
}
if (item.payload.op === 'DEL') {
delete this._index[item.payload.key]
return
}
}
}
}

Expand Down