mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: more efficient
This commit is contained in:
1 parent
ebbdbc53a4
commit
d780d32291
2 files changed
+25
-42
No files matched your search
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
"build:docs": "vitepress build docs",
|
"build:docs": "vitepress build docs",
|
||||||
"build:ratingleaderboard": "vite-node --script scripts/buildRatingLeaderboard",
|
"build:ratingleaderboard": "vite-node --script scripts/buildRatingLeaderboard",
|
||||||
"build:assets": "vite-node --max_old_space_size=16384 --script scripts/buildAssets/index",
|
"build:assets": "vite-node --max_old_space_size=16384 --script scripts/buildAssets/index",
|
||||||
"build:test": "vite-node --script scripts/buildTest",
|
"test": "vite-node --script scripts/test",
|
||||||
"dev:bot": "vite-node --script scripts/build && yarn start:bot",
|
"dev:bot": "vite-node --script scripts/build && yarn start:bot",
|
||||||
"dev:docs": "vitepress dev docs",
|
"dev:docs": "vitepress dev docs",
|
||||||
"dev:website": "next dev",
|
"dev:website": "next dev",
|
||||||
|
|||||||
@@ -18,48 +18,36 @@ const PLAYERS_PER_CHUNK = 256;
|
|||||||
const CHUNKS_PER_BATCH = 128;
|
const CHUNKS_PER_BATCH = 128;
|
||||||
|
|
||||||
const production = argv.includes('--production');
|
const production = argv.includes('--production');
|
||||||
const users = usersRaw; //.slice(0, 10);
|
const region = argv
|
||||||
|
.find((argument) => argument.startsWith('--region'))
|
||||||
|
?.split('=')[1] as Region | undefined;
|
||||||
|
|
||||||
let done = 0;
|
if (!region || !REGIONS.includes(region)) {
|
||||||
const regionSortedUsers = REGIONS.map((region) => ({
|
throw new Error('No valid region specified');
|
||||||
region,
|
}
|
||||||
users: users.filter((user) => idToRegion(user.blitz) === region),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const todayPath = `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`;
|
const todayPath = `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`;
|
||||||
const bases: Partial<Record<Region, number>> = {};
|
const users = usersRaw.filter(({ blitz }) => idToRegion(blitz) === region);
|
||||||
const chunks = regionSortedUsers
|
const base = Math.ceil(users.length / PLAYERS_PER_CHUNK);
|
||||||
.map(({ region, users }) => {
|
const chunks = times(base, (offset) => ({
|
||||||
const base = Math.ceil(users.length / PLAYERS_PER_CHUNK);
|
offset,
|
||||||
bases[region] = base;
|
users: users.filter((user) => user.blitz % base === offset),
|
||||||
|
}));
|
||||||
return times(base, (offset) => {
|
|
||||||
return {
|
|
||||||
region,
|
|
||||||
offset,
|
|
||||||
users: users.filter((user) => user.blitz % base === offset),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.flat();
|
|
||||||
const batches = chunk(chunks, CHUNKS_PER_BATCH);
|
const batches = chunk(chunks, CHUNKS_PER_BATCH);
|
||||||
|
const manifestWriteStream = new RtsmWriteStream();
|
||||||
const manifests = Object.entries(bases).map(([region, base]) => {
|
|
||||||
const writeStream = new RtsmWriteStream();
|
|
||||||
|
|
||||||
writeStream.rtsm(base);
|
|
||||||
|
|
||||||
return {
|
|
||||||
encoding: 'base64',
|
|
||||||
path: `regions/${region}/regular/tanks/${todayPath}/manifest.rtsm`,
|
|
||||||
content: Buffer.from(compress(writeStream.uint8Array)).toString('base64'),
|
|
||||||
} satisfies FileChange;
|
|
||||||
});
|
|
||||||
|
|
||||||
await commitAssets(
|
await commitAssets(
|
||||||
`regular tank stats manifests ${todayPath}`,
|
`regular tank stats manifests ${todayPath}`,
|
||||||
manifests,
|
[
|
||||||
|
{
|
||||||
|
encoding: 'base64',
|
||||||
|
path: `regions/${region}/regular/tanks/${todayPath}/manifest.rtsm`,
|
||||||
|
content: Buffer.from(
|
||||||
|
compress(manifestWriteStream.rtsm(base).uint8Array),
|
||||||
|
).toString('base64'),
|
||||||
|
},
|
||||||
|
],
|
||||||
production,
|
production,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -76,11 +64,7 @@ for (const batch of batches) {
|
|||||||
let playersDone = 0;
|
let playersDone = 0;
|
||||||
const players = await Promise.all(
|
const players = await Promise.all(
|
||||||
chunk.users.map(async (user) => {
|
chunk.users.map(async (user) => {
|
||||||
const tanks = await getTankStats(
|
const tanks = await getTankStats(region, user.blitz, Locale.EnglishUS);
|
||||||
chunk.region,
|
|
||||||
user.blitz,
|
|
||||||
Locale.EnglishUS,
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(`Player ${++playersDone} of ${chunk.users.length}`);
|
console.log(`Player ${++playersDone} of ${chunk.users.length}`);
|
||||||
|
|
||||||
@@ -98,7 +82,7 @@ for (const batch of batches) {
|
|||||||
changes.push({
|
changes.push({
|
||||||
encoding: 'base64',
|
encoding: 'base64',
|
||||||
content: Buffer.from(compress(writeStream.uint8Array)).toString('base64'),
|
content: Buffer.from(compress(writeStream.uint8Array)).toString('base64'),
|
||||||
path: `regions/${chunk.region}/regular/tanks/${todayPath}/${chunk.offset}.rtsc.lz4`,
|
path: `regions/${region}/regular/tanks/${todayPath}/${chunk.offset}.rtsc.lz4`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +91,5 @@ for (const batch of batches) {
|
|||||||
`regular tank stats ${todayPath} batch ${batches.indexOf(batch) + 1}`,
|
`regular tank stats ${todayPath} batch ${batches.indexOf(batch) + 1}`,
|
||||||
changes,
|
changes,
|
||||||
production,
|
production,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user