import { performance } from 'node:perf_hooks' import { openDb, seed } from '../server/db.js' import { Service } from '../server/service.js' const db = openDb(':memory:') seed(db) const s = new Service(db), admin = s.user('admin'), statuses = s.queue('support').statuses const ticket = db.prepare( 'INSERT INTO tickets(subject,customer,customer_name,queue_id,status_id,created_at,updated_at) VALUES(?,?,?,?,?,?,?)', ), message = db.prepare( 'INSERT INTO messages(id,ticket_id,kind,sender,recipient,body,message_id,created_at) VALUES(?,?,?,?,?,?,?,?)', ) const started = performance.now(), at = '2026-01-01T12:00:00.000Z' db.transaction(() => { for (let i = 0; i < 50000; i++) { const id = Number( ticket.run( 'Benchmark ' + i, 'customer@example.invalid', 'Testkontakt', 'support', statuses[i % 10 === 0 ? 6 : 1].id, at, at, ).lastInsertRowid, ) message.run( 'benchmark-' + i, id, 'incoming', 'customer@example.invalid', 'support@syncova.local', 'Benchmark Nachricht zur Wartung von Arbeitsplatz und Server. '.repeat(8), '', at, ) } })() console.log(JSON.stringify({ tickets: 50000, setupMs: Math.round(performance.now() - started) })) for (const [name, filters] of [ ['ersteSeite', { queue: 'support', view: 'inbox' }], ['tiefeSeite', { queue: 'support', view: 'inbox', page: 1000 }], ['sortierteSeite', { queue: 'support', view: 'inbox', sort: 'newest' }], ['volltext', { queue: 'support', view: 'inbox', q: 'Benchmark' }], ]) { const timings = [] let result for (let j = 0; j < 5; j++) { const start = performance.now() result = s.ticketPage(admin, filters) timings.push(performance.now() - start) } console.log( JSON.stringify({ name, page: result.page, total: result.total, items: result.items.length, jsonBytes: Buffer.byteLength(JSON.stringify(result)), medianMs: Math.round(timings.sort((a, b) => a - b)[2] * 10) / 10, }), ) } db.close()