mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: efficient pre-chunking
This commit is contained in:
1 parent
604345d909
commit
88d8f4f14b
1 file changed
+18
-11
+18
-11
@@ -1,4 +1,4 @@
|
|||||||
import { times } from 'lodash';
|
import { chunk, times } from 'lodash';
|
||||||
import { argv } from 'process';
|
import { argv } from 'process';
|
||||||
import { Region, REGIONS } from '../src/constants/regions';
|
import { Region, REGIONS } from '../src/constants/regions';
|
||||||
import { getAccountInfo } from '../src/core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../src/core/blitz/getAccountInfo';
|
||||||
@@ -30,10 +30,19 @@ const PLAYER_IDS_PER_CALL = 100;
|
|||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
const production = argv.includes('--production');
|
const production = argv.includes('--production');
|
||||||
const preDiscoveredIds = await fetchPreDiscoveredIds(!production);
|
const preDiscoveredIds = await fetchPreDiscoveredIds(!production);
|
||||||
const playerIds: Record<Region, number[]> = {
|
const playerIds: Record<Region, number[][]> = {
|
||||||
asia: preDiscoveredIds.filter((id) => idToRegion(id) === 'asia'),
|
asia: chunk(
|
||||||
com: preDiscoveredIds.filter((id) => idToRegion(id) === 'com'),
|
preDiscoveredIds.filter((id) => idToRegion(id) === 'asia'),
|
||||||
eu: preDiscoveredIds.filter((id) => idToRegion(id) === 'eu'),
|
PLAYER_IDS_PER_CALL,
|
||||||
|
),
|
||||||
|
com: chunk(
|
||||||
|
preDiscoveredIds.filter((id) => idToRegion(id) === 'com'),
|
||||||
|
PLAYER_IDS_PER_CALL,
|
||||||
|
),
|
||||||
|
eu: chunk(
|
||||||
|
preDiscoveredIds.filter((id) => idToRegion(id) === 'eu'),
|
||||||
|
PLAYER_IDS_PER_CALL,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
let regionIndex = 0;
|
let regionIndex = 0;
|
||||||
let checkedPlayers = 0;
|
let checkedPlayers = 0;
|
||||||
@@ -47,16 +56,14 @@ times(THREADS, async () => {
|
|||||||
while (availableRegions.length > 0 && startTime + RUN_TIME > Date.now()) {
|
while (availableRegions.length > 0 && startTime + RUN_TIME > Date.now()) {
|
||||||
const region = availableRegions[regionIndex];
|
const region = availableRegions[regionIndex];
|
||||||
const regionIds = playerIds[region];
|
const regionIds = playerIds[region];
|
||||||
const initialLength = regionIds.length;
|
const [ids] = regionIds.splice(
|
||||||
const idIndex = Math.min(
|
Math.floor(Math.random() * regionIds.length),
|
||||||
Math.floor(initialLength * Math.random()),
|
1,
|
||||||
initialLength - 2,
|
|
||||||
);
|
);
|
||||||
const ids = playerIds[region].splice(idIndex, PLAYER_IDS_PER_CALL);
|
|
||||||
checkedPlayers += PLAYER_IDS_PER_CALL;
|
|
||||||
const accountInfo = await getAccountInfo(region, ids, undefined, {
|
const accountInfo = await getAccountInfo(region, ids, undefined, {
|
||||||
fields: 'last_battle_time,statistics.all.battles',
|
fields: 'last_battle_time,statistics.all.battles',
|
||||||
});
|
});
|
||||||
|
checkedPlayers += ids.length;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass rates
|
* Pass rates
|
||||||
|
|||||||
Reference in new issue
Block a user