From 9c7d04679ccf169590647b58e672590dfde7c993 Mon Sep 17 00:00:00 2001 From: mawahl Date: Thu, 28 Sep 2023 08:14:46 +0200 Subject: [PATCH] Temp commit 2 --- scripts/seed-users.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/scripts/seed-users.ts b/scripts/seed-users.ts index d23fc2a9e14..6462f66e489 100644 --- a/scripts/seed-users.ts +++ b/scripts/seed-users.ts @@ -31,6 +31,19 @@ async function refresh(): Promise { keycloak.refreshToken = refresh_token; } +function createUserObject(index: number): Object { + const firstName = faker.person.firstName(); + const lastName = faker.person.lastName(); + const user = { + realm: 'foobar', + username: `${index}.${lastName}@sp-sh.de`, + firstName, + lastName, + email: `${index}.${lastName}@sp-sh.de`, + }; + return user; +} + async function createUser(index: number): Promise { const firstName = faker.person.firstName(); const lastName = faker.person.lastName(); @@ -61,13 +74,25 @@ async function createUser(index: number): Promise { async function main(): Promise { await login(); - const count = keycloak.users.count({ realm: 'foobar' }); - console.log(`${count} users in the foobar realm.`); + // const count = keycloak.users.count({ realm: 'foobar' }); + // console.log(`${count} users in the foobar realm.`); + + for( let i = 0; i < 100_000; i += 1){ + try { + if((i % 5000 === 0)){ + await login(); + } + await keycloak.users.create(createUserObject(i)); + } catch (err) { + console.error(err); + } + } + // let k = 0; // for (let i = 0; i < 100; i += 1) { // const tasks = new Array>(); // for (let j = 0; j < 1_000; j += 1) { - // tasks.push(createUser(j + j * i)); + // tasks.push(createUser(k += 1)); // } // await Promise.allSettled(tasks); // }