Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: performance improvements
Browse files Browse the repository at this point in the history
mrnagydavid committed Oct 18, 2024
1 parent d95257c commit 85f2631
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/redisHashKeyValueDB.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import {
IncrementTuple,
KeyValueDBTuple,
} from '@naturalcycles/db-lib'
import { _chunk } from '@naturalcycles/js-lib'
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
import { RedisKeyValueDBCfg } from './redisKeyValueDB'

@@ -70,10 +69,9 @@ export class RedishHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
.hscanStream(table)
.flatMap(keyValueList => {
const keys: string[] = []
keyValueList.forEach((keyOrValue, index) => {
if (index % 2 !== 0) return
keys.push(keyOrValue)
})
for (let i = 0; i < keyValueList.length; i += 2) {
keys.push(keyValueList[i]!)
}
return keys
})
.take(limit || Infinity)
@@ -85,12 +83,12 @@ export class RedishHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
return this.cfg.client
.hscanStream(table)
.flatMap(keyValueList => {
const values: string[] = []
keyValueList.forEach((keyOrValue, index) => {
if (index % 2 !== 1) return
values.push(keyOrValue)
})
return values.map(v => Buffer.from(v))
const values: Buffer[] = []
for (let i = 0; i < keyValueList.length; i += 2) {
const value = Buffer.from(keyValueList[i + 1]!)
values.push(value)
}
return values
})
.take(limit || Infinity)
}
@@ -99,10 +97,13 @@ export class RedishHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
return this.cfg.client
.hscanStream(table)
.flatMap(keyValueList => {
const entries = _chunk(keyValueList, 2) as [string, string][]
return entries.map(([k, v]) => {
return [k, Buffer.from(String(v))] satisfies KeyValueDBTuple
})
const entries: [string, Buffer][] = []
for (let i = 0; i < keyValueList.length; i += 2) {
const key = keyValueList[i]!
const value = Buffer.from(keyValueList[i + 1]!)
entries.push([key, value])
}
return entries
})
.take(limit || Infinity)
}

0 comments on commit 85f2631

Please sign in to comment.