Skip to content

Commit 8bf6fdb

Browse files
johnreesmschneider
authored andcommitted
fix: api rate-limiter
fixes #103
1 parent 7db9897 commit 8bf6fdb

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

scripts/api.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,24 @@ export async function getGovernanceAccounts<TAccount extends GovernanceAccount>(
6969
)
7070
}
7171

72-
const promises: Promise<Record<string, ParsedAccount<TAccount>>>[] = []
73-
// workaround for preventing getting rate limited by public node
74-
// 1/ for of instead of map +
75-
// 2/ sleep a bit
72+
let accounts: Record<string, ParsedAccount<TAccount>> = {}
73+
7674
for (const at of accountTypes) {
77-
await new Promise((r) => setTimeout(r, 3000))
78-
promises.push(
79-
getGovernanceAccountsImpl<TAccount>(
75+
accounts = {
76+
...accounts,
77+
...(await getGovernanceAccountsImpl(
8078
programId,
8179
endpoint,
8280
accountClass,
8381
at,
8482
filters
85-
)
86-
)
83+
)),
84+
}
85+
// XXX: sleep to prevent public RPC rate limits
86+
await new Promise((r) => setTimeout(r, 3_000))
8787
}
8888

89-
const all = await Promise.all(promises)
90-
91-
return all.reduce((res, r) => ({ ...res, ...r }), {})
89+
return accounts
9290
}
9391

9492
async function getGovernanceAccountsImpl<TAccount extends GovernanceAccount>(

0 commit comments

Comments
 (0)