♻️ prettier and refactor page siwe (#438)
This commit is contained in:
committed by
ericlinagora
parent
93353d32af
commit
ed7c836889
@@ -22,11 +22,12 @@ type Options = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const waitTimeoutMS = (ms: number) => ms > 0 && new Promise(r => setTimeout(r, ms));
|
const waitTimeoutMS = (ms: number) => ms > 0 && new Promise(r => setTimeout(r, ms));
|
||||||
|
const defaultPageSize = "100";
|
||||||
|
|
||||||
async function iterateOverRepoPages<Entity>(
|
async function iterateOverRepoPages<Entity>(
|
||||||
repository: Repository<Entity>,
|
repository: Repository<Entity>,
|
||||||
forEachPage: (entities: Entity[]) => Promise<void>,
|
forEachPage: (entities: Entity[]) => Promise<void>,
|
||||||
pageSizeAsStringForReasons: string = "100",
|
pageSizeAsStringForReasons: string = defaultPageSize,
|
||||||
filter: FindFilter = {},
|
filter: FindFilter = {},
|
||||||
delayPerPageMS: number = 200,
|
delayPerPageMS: number = 200,
|
||||||
) {
|
) {
|
||||||
@@ -79,24 +80,16 @@ class SearchIndexAll {
|
|||||||
CompanyUser,
|
CompanyUser,
|
||||||
);
|
);
|
||||||
let count = 0;
|
let count = 0;
|
||||||
await iterateOverRepoPages(
|
await iterateOverRepoPages(repository, async entities => {
|
||||||
repository,
|
for (const user of entities) {
|
||||||
async entities => {
|
const companies = await companiesUsersRepository.find({ user_id: user.id }, {}, undefined);
|
||||||
for (const user of entities) {
|
user.cache ||= { companies: [] };
|
||||||
const companies = await companiesUsersRepository.find(
|
user.cache.companies = companies.getEntities().map(company => company.group_id);
|
||||||
{ user_id: user.id },
|
await repository.save(user, undefined);
|
||||||
{},
|
}
|
||||||
undefined,
|
count += entities.length;
|
||||||
);
|
options.spinner.start(`Adding companies to cache of ${count} users...`);
|
||||||
user.cache ||= { companies: [] };
|
});
|
||||||
user.cache.companies = companies.getEntities().map(company => company.group_id);
|
|
||||||
await repository.save(user, undefined);
|
|
||||||
}
|
|
||||||
count += entities.length;
|
|
||||||
options.spinner.start(`Adding companies to cache of ${count} users...`);
|
|
||||||
},
|
|
||||||
"2",
|
|
||||||
);
|
|
||||||
options.spinner.succeed(`Added companies to cache of ${count} users`);
|
options.spinner.succeed(`Added companies to cache of ${count} users`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user