MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / processBuffer

Method processBuffer

packages/db/src/buffers/bot-buffer.ts:46–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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}

Callers 4

constructorMethod · 0.95

Calls 3

reportFlushStatsMethod · 0.80
jsonEachRowStreamMethod · 0.80
getClickhouseSettingsMethod · 0.80

Tested by

no test coverage detected