Skip to content

Commit

Permalink
Temp commit 2
Browse files Browse the repository at this point in the history
  • Loading branch information
WahlMartin committed Sep 28, 2023
1 parent 952075c commit 9c7d046
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions scripts/seed-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ async function refresh(): Promise<void> {
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<void> {
const firstName = faker.person.firstName();
const lastName = faker.person.lastName();
Expand Down Expand Up @@ -61,13 +74,25 @@ async function createUser(index: number): Promise<void> {
async function main(): Promise<void> {
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<Promise<void>>();
// for (let j = 0; j < 1_000; j += 1) {
// tasks.push(createUser(j + j * i));
// tasks.push(createUser(k += 1));
// }
// await Promise.allSettled(tasks);
// }
Expand Down

0 comments on commit 9c7d046

Please sign in to comment.