From ed7c836889f614a2f27ebdd4b04bdbf93996c0cd Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Tue, 26 Mar 2024 12:06:22 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20prettier=20and=20refact?= =?UTF-8?q?or=20page=20siwe=20(#438)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/cli/cmds/search_cmds/index_all.ts | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts b/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts index 3f0e66ab..efc2b774 100644 --- a/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts +++ b/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts @@ -22,11 +22,12 @@ type Options = { }; const waitTimeoutMS = (ms: number) => ms > 0 && new Promise(r => setTimeout(r, ms)); +const defaultPageSize = "100"; async function iterateOverRepoPages( repository: Repository, forEachPage: (entities: Entity[]) => Promise, - pageSizeAsStringForReasons: string = "100", + pageSizeAsStringForReasons: string = defaultPageSize, filter: FindFilter = {}, delayPerPageMS: number = 200, ) { @@ -79,24 +80,16 @@ class SearchIndexAll { CompanyUser, ); let count = 0; - await iterateOverRepoPages( - repository, - async entities => { - for (const user of entities) { - const companies = await companiesUsersRepository.find( - { user_id: user.id }, - {}, - undefined, - ); - 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", - ); + await iterateOverRepoPages(repository, async entities => { + for (const user of entities) { + const companies = await companiesUsersRepository.find({ user_id: user.id }, {}, undefined); + 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...`); + }); options.spinner.succeed(`Added companies to cache of ${count} users`); }