()
| 167 | } |
| 168 | |
| 169 | async processBuffer(): Promise<void> { |
| 170 | const lrangeStart = performance.now(); |
| 171 | const items = await this.redis.lrange(this.redisKey, 0, this.batchSize - 1); |
| 172 | const lrangeMs = performance.now() - lrangeStart; |
| 173 | |
| 174 | if (items.length === 0) { |
| 175 | this.reportFlushStats({ rowsProcessed: 0, phases: { lrangeMs } }); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | // Raw passthrough: each Redis entry is already a valid JSONEachRow |
| 180 | // line. Streaming raw strings to CH skips JSON.parse + the client's |
| 181 | // re-stringify on the hot path. |
| 182 | const chStart = performance.now(); |
| 183 | await this.parallelLimit(this.chunks(items, this.chunkSize), (chunk) => |
| 184 | ch.insert({ |
| 185 | table: TABLE_NAMES.groups, |
| 186 | values: this.jsonEachRowStream(chunk), |
| 187 | format: 'JSONEachRow', |
| 188 | clickhouse_settings: this.getClickhouseSettings(), |
| 189 | }), |
| 190 | ); |
| 191 | const chInsertMs = performance.now() - chStart; |
| 192 | |
| 193 | const trimStart = performance.now(); |
| 194 | await this.redis.ltrim(this.redisKey, items.length, -1); |
| 195 | const trimMs = performance.now() - trimStart; |
| 196 | |
| 197 | this.reportFlushStats({ |
| 198 | rowsProcessed: items.length, |
| 199 | phases: { lrangeMs, chInsertMs, trimMs }, |
| 200 | }); |
| 201 | } |
| 202 | } |
no test coverage detected