mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 19:30:38 +08:00
Handle subgraph API quota exhaustion
We had to improve the logic when the subgraph API quota has been exhausted. Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
+13
-5
@@ -203,16 +203,24 @@ export class Org {
|
||||
GetSafesByOwners,
|
||||
{ owners: [owner] },
|
||||
);
|
||||
const safes = safesByOwner.safes.reduce(
|
||||
(prev: any, curr: Safe) => prev.concat(curr.id),
|
||||
[],
|
||||
);
|
||||
|
||||
let safes = [];
|
||||
if (safesByOwner && safesByOwner.safes.length > 0) {
|
||||
safes = safesByOwner.safes.reduce(
|
||||
(prev: any, curr: Safe) => prev.concat(curr.id),
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
const orgsByOwner = await utils.querySubgraph(
|
||||
config.orgs.subgraph,
|
||||
GetOrgsByOwners,
|
||||
{ owners: [...safes, owner] },
|
||||
);
|
||||
const orgs: { id: string; owner: string }[] = [...orgsByOwner.orgs];
|
||||
let orgs: { id: string; owner: string }[] = [];
|
||||
if (orgsByOwner && orgsByOwner.orgs) {
|
||||
orgs = [...orgsByOwner.orgs];
|
||||
}
|
||||
|
||||
return orgs.map(o => new Org(o.id, o.owner));
|
||||
}
|
||||
|
||||
+9
-6
@@ -377,7 +377,7 @@ export async function querySubgraphWithRetry(
|
||||
query: string,
|
||||
variables: Record<string, any>,
|
||||
retries = 3,
|
||||
): Promise<null | any> {
|
||||
): Promise<Record<string, any> | null> {
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -393,11 +393,14 @@ export async function querySubgraphWithRetry(
|
||||
if (json.errors) {
|
||||
console.error("querySubgraph:", json.errors);
|
||||
|
||||
if (retries > 0) querySubgraphWithRetry(url, query, variables, retries - 1);
|
||||
else return null;
|
||||
if (retries > 0) {
|
||||
return querySubgraphWithRetry(url, query, variables, retries - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return json.data;
|
||||
}
|
||||
|
||||
return json.data;
|
||||
}
|
||||
|
||||
export const querySubgraph = cache.cached(
|
||||
@@ -589,7 +592,7 @@ export async function isSafe(
|
||||
addr: address.toLowerCase(),
|
||||
});
|
||||
|
||||
return query.safe !== null ? true : false;
|
||||
return query?.safe !== null ? true : false;
|
||||
}
|
||||
|
||||
// Get a Gnosis Safe at an address.
|
||||
|
||||
Reference in New Issue
Block a user