()
| 44 | } |
| 45 | |
| 46 | async processBuffer() { |
| 47 | const lrangeStart = performance.now(); |
| 48 | const events = await this.redis.lrange( |
| 49 | this.redisKey, |
| 50 | 0, |
| 51 | this.batchSize - 1 |
| 52 | ); |
| 53 | const lrangeMs = performance.now() - lrangeStart; |
| 54 | |
| 55 | if (events.length === 0) { |
| 56 | this.reportFlushStats({ rowsProcessed: 0, phases: { lrangeMs } }); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | // Raw passthrough: each Redis entry is already a valid JSONEachRow |
| 61 | // line. Streaming raw strings skips JSON.parse + the client's |
| 62 | // re-stringify on the hot path. |
| 63 | const chStart = performance.now(); |
| 64 | await ch.insert({ |
| 65 | table: TABLE_NAMES.events_bots, |
| 66 | values: this.jsonEachRowStream(events), |
| 67 | format: 'JSONEachRow', |
| 68 | clickhouse_settings: this.getClickhouseSettings(), |
| 69 | }); |
| 70 | const chInsertMs = performance.now() - chStart; |
| 71 | |
| 72 | const trimStart = performance.now(); |
| 73 | await this.redis.ltrim(this.redisKey, events.length, -1); |
| 74 | const trimMs = performance.now() - trimStart; |
| 75 | |
| 76 | this.reportFlushStats({ |
| 77 | rowsProcessed: events.length, |
| 78 | phases: { lrangeMs, chInsertMs, trimMs }, |
| 79 | }); |
| 80 | } |
| 81 | } |
no test coverage detected