Skip to content

Commit

Permalink
Remove max limit on attestions in Avenue api (#300)
Browse files Browse the repository at this point in the history
* Add new pagination method
  • Loading branch information
amrro authored Nov 23, 2022
1 parent 76ee6be commit ec542f8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
Binary file modified apps/govrn-contract-subgraph/build/Govrn/Govrn.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions apps/govrn-contract-subgraph/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Attestation, Contribution } from '../generated/schema';

export function handleAttest(event: Attest): void {
let entity = Attestation.load(
`${event.params.attestor}-${event.params.contribution}`,
`${event.params.attestor.toHex()}-${event.params.contribution.toHex()}`,
);

if (!entity) {
entity = new Attestation(
`${event.params.attestor}-${event.params.contribution}`,
`${event.params.attestor.toHex()}-${event.params.contribution.toHex()}`,
);
}

Expand Down
35 changes: 28 additions & 7 deletions apps/voyager-identity-api/src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { LDContribution } from './types';
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;
const CHAIN_URL = process.env.CHAIN_URL;
const CHAIN_ID = Number(process.env.CHAIN_ID);
const SKIP_LIMIT = 4999;

const LIMIT = 100;
const SKIP_LIMIT = 4999;

const networkConfig: NetworkConfig = {
address: CONTRACT_ADDRESS,
Expand All @@ -21,6 +21,7 @@ export const requestSchema = object({
address: string().required(),
page: number().optional().default(1),
limit: number().optional().default(LIMIT),
after: number().optional().default(0),
});

const provider = new ethers.providers.JsonRpcProvider(CHAIN_URL);
Expand All @@ -31,18 +32,38 @@ export const loadContributions = async ({
address,
limit,
page,
after,
}: InferType<typeof requestSchema>): Promise<LDContribution[]> => {
const skip = (page - 1) * limit;

if (skip > SKIP_LIMIT) {
throw new Error('Maximum Limit exceeded.');
throw new Error(
'Maximum Limit exceeded. Please use the last id param vs skip',
);
}
if (skip && after) {
throw new Error('Both skip and after cannot be provided');
}

const contrsEvents = (
await client.listContributions({
where: { address },
})
).contributions;
let contrsEvents = [];
if (after) {
contrsEvents = (
await client.listContributions({
first: limit,
where: { address, id_gt: String(after) },
orderBy: 'id',
})
).contributions;
} else {
contrsEvents = (
await client.listContributions({
first: limit,
skip,
where: { address },
orderBy: 'id',
})
).contributions;
}

const x = await Promise.all(
contrsEvents.map(async e => {
Expand Down
7 changes: 3 additions & 4 deletions kubernetes/prod/voyager_identity_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ spec:
value: 'https://api.thegraph.com/subgraphs/name/govrn-hq/govrn-protocol-gnosis'
- name: CONTRACT_ADDRESS
value: '0x8a33e6288d155aDB1d368838CB91E01d30C66eC1'
- name: CHAIN_ID
value: 100
- name: CHAIN_URL
valueFrom:
secretKeyRef:
name: voyager-identity-api
key: chain_url
value: 'https://rpc.gnosischain.com/'
resources:
requests:
memory: 300Mi
Expand Down
7 changes: 3 additions & 4 deletions kubernetes/staging/voyager_identity_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ spec:
value: 'https://api.thegraph.com/subgraphs/name/govrn-hq/govrn-protocol-gnosis'
- name: CONTRACT_ADDRESS
value: '0x8a33e6288d155aDB1d368838CB91E01d30C66eC1'
- name: CHAIN_ID
value: 100
- name: CHAIN_URL
valueFrom:
secretKeyRef:
name: voyager-identity-api
key: chain_url
value: 'https://rpc.gnosischain.com/'
resources:
requests:
memory: 300Mi
Expand Down

0 comments on commit ec542f8

Please sign in to comment.