From 2aea5a523c4f5bd3cd6fc7ca3e6ab35354d24f55 Mon Sep 17 00:00:00 2001 From: siiky Date: Mon, 2 Jun 2025 17:04:56 +0100 Subject: [PATCH] fix: creating large number of fake machines --- packages/server/tests/stress/machines.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/server/tests/stress/machines.js b/packages/server/tests/stress/machines.js index 9e9605b1..7f3e75ac 100644 --- a/packages/server/tests/stress/machines.js +++ b/packages/server/tests/stress/machines.js @@ -44,17 +44,18 @@ const save_machines_to_db = async (machines, replace_existing) => { if (replace_existing) await db.none('DELETE FROM devices') console.log('inserting machines into DB') - db.tx(tx => - tx.batch( - machines.map(device_id => - tx.none( - `INSERT INTO devices (device_id, cassette1, cassette2, paired, display, created, name, last_online, location) - VALUES ($1, 0, 0, 't', 't', now(), $2, now(), '{}'::json)`, - [device_id, device_id], + for (const ids of chunk(machines, 20)) + await db.tx(tx => + tx.batch( + ids.map(device_id => + tx.none( + `INSERT INTO devices (device_id, cassette1, cassette2, paired, display, created, name, last_online, location) + VALUES ($1, 0, 0, 't', 't', now(), $1, now(), '{}'::json)`, + [device_id], + ), ), ), - ), - ) + ) } const save_device_ids_to_file = async (