fix: creating large number of fake machines

This commit is contained in:
siiky 2025-06-02 17:04:56 +01:00
parent 5feee6d5df
commit 2aea5a523c

View file

@ -44,17 +44,18 @@ const save_machines_to_db = async (machines, replace_existing) => {
if (replace_existing) await db.none('DELETE FROM devices') if (replace_existing) await db.none('DELETE FROM devices')
console.log('inserting machines into DB') console.log('inserting machines into DB')
db.tx(tx => for (const ids of chunk(machines, 20))
tx.batch( await db.tx(tx =>
machines.map(device_id => tx.batch(
tx.none( ids.map(device_id =>
`INSERT INTO devices (device_id, cassette1, cassette2, paired, display, created, name, last_online, location) tx.none(
VALUES ($1, 0, 0, 't', 't', now(), $2, now(), '{}'::json)`, `INSERT INTO devices (device_id, cassette1, cassette2, paired, display, created, name, last_online, location)
[device_id, device_id], VALUES ($1, 0, 0, 't', 't', now(), $1, now(), '{}'::json)`,
[device_id],
),
), ),
), ),
), )
)
} }
const save_device_ids_to_file = async ( const save_device_ids_to_file = async (