feat: finish script

This commit is contained in:
TrèsAbhi committed 2024-06-28 14:12:58 -05:00
1 parent 33012f9f21
commit ffaa368f81
3 files changed
+103 -70

No files matched your search

+1 -5
View File
@@ -33,7 +33,7 @@ async function manageQueue() {
if (queue.length > 0 && inProgress < MAX_CALLS_PER_SECOND) {
inProgress++;
const timeout = setTimeout(() => decrement, 1000);
const timeout = setTimeout(decrement, 1000);
const request = queue.shift()!;
const data = (await patientFetch(request.url)
.then((response) => response.json())
@@ -45,10 +45,6 @@ async function manageQueue() {
request.resolve(data.data);
} else {
if (RETRY_ERRORS.includes(data.error.message)) {
console.log(
`Encountered retry-able error ${data.error}, putting "${request.url}" back in queue...`,
);
retryAbleBlitzFetchEvent.emit(undefined);
clearTimeout(timeout);
setTimeout(() => {
+10 -12
View File
@@ -1,21 +1,23 @@
import { times } from 'lodash';
import { decompress } from 'lz4js';
import ProgressBar from 'progress';
import { DiscoverIdsManifest } from '../../../scripts/discoverIds';
import { DidsReadStream } from '../streams/dids';
import { asset } from './asset';
export async function fetchPreDiscoveredIds(dev: boolean) {
const idChunks: number[][] = [];
const preDiscoveredManifest = (await fetch(
asset('ids/manifest.json', dev),
).then((response) => response.json())) as DiscoverIdsManifest;
console.log(
`Fetching ${preDiscoveredManifest.chunks} pre-discovered chunks...`,
const manifest = (await fetch(asset('ids/manifest.json', dev)).then(
(response) => response.json(),
)) as DiscoverIdsManifest;
const bar = new ProgressBar(
`Fetching ${manifest.count.toLocaleString()} ids in ${manifest.chunks} chunks :bar`,
manifest.chunks,
);
bar.render();
await Promise.all(
times(preDiscoveredManifest.chunks, async (chunkIndex) => {
times(manifest.chunks, async (chunkIndex) => {
const preDiscovered = await fetch(
asset(`ids/${chunkIndex}.dids.lz4`, dev),
).then(async (response) => {
@@ -24,12 +26,8 @@ export async function fetchPreDiscoveredIds(dev: boolean) {
return new DidsReadStream(decompressed as ArrayBuffer).dids();
});
// no spread syntax: https://github.com/oven-sh/bun/issues/11734
idChunks.push(preDiscovered);
console.log(
`Pre-discovered ${preDiscovered.length} ids (chunk ${chunkIndex})`,
);
bar.tick();
}),
);