Skip to content

Commit

Permalink
Merge pull request #18011 from mozilla/inactive-uids-concurrency
Browse files Browse the repository at this point in the history
chore(script): add concurrency to inactive uids script
  • Loading branch information
chenba authored Nov 14, 2024
2 parents 616c182 + 4b7d223 commit a1b137c
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { performance } from 'perf_hooks';
import { Command } from 'commander';
import { StatsD } from 'hot-shots';
import { Container } from 'typedi';
import PQueue from 'p-queue-compat';

import { parseDryRun } from '../lib/args';
import { AppConfig, AuthFirestore, AuthLogger } from '../../lib/types';
Expand Down Expand Up @@ -107,6 +108,11 @@ const init = async () => {
'The number of results per accounts DB query. Defaults to 100000.',
parseInt
)
.option(
'--concurrency [number]',
'The number inflight active checks. Defaults to 6.',
parseInt
)
.option('--perf-stats [true|false]', 'Print out performance stats.', false);

program.parse(process.argv);
Expand Down Expand Up @@ -253,6 +259,10 @@ const init = async () => {
}

const fd = fs.openSync(filepath, 'a');
const concurrency = program.concurrency || 6;
const queue = new PQueue({
concurrency,
});

let hasMaxResultsCount = true;
let totalRowsReturned = 0;
Expand All @@ -271,10 +281,15 @@ const init = async () => {

const inactiveUids: string[] = [];
for (const accountRecord of accounts) {
if (!(await isActive(accountRecord))) {
inactiveUids.push(accountRecord.uid);
}
await queue.onSizeLessThan(concurrency * 5);

queue.add(async () => {
if (!(await isActive(accountRecord))) {
inactiveUids.push(accountRecord.uid);
}
});
}
await queue.onIdle();

if (inactiveUids.length) {
totalInactiveAccounts += inactiveUids.length;
Expand Down

0 comments on commit a1b137c

Please sign in to comment.