From 1ffc353afda87d181aa4b8a5c68fada26b8c1f3b Mon Sep 17 00:00:00 2001 From: Huss Martinez Date: Thu, 10 Apr 2025 10:57:36 +0700 Subject: [PATCH] fix: donations query pagination --- packages/data-layer/src/data-layer.ts | 31 +++++++++++++++++++-------- packages/data-layer/src/queries.ts | 9 +++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/packages/data-layer/src/data-layer.ts b/packages/data-layer/src/data-layer.ts index d36369519..8decd50e7 100644 --- a/packages/data-layer/src/data-layer.ts +++ b/packages/data-layer/src/data-layer.ts @@ -816,17 +816,30 @@ export class DataLayer { chainIds: number[]; }): Promise { const { address, chainIds } = args; - const response: { donations: Contribution[] } = await request( - this.gsIndexerEndpoint, - getDonationsByDonorAddress, - { - address: getAddress(address), - chainIds, - }, - ); + let offset = 0; + let hasMore = true; + const limit = 200; + let donations: Contribution[] = []; + + while (hasMore) { + const response: { donations: Contribution[] } = await request( + this.gsIndexerEndpoint, + getDonationsByDonorAddress, + { address: getAddress(address), chainIds, limit, offset }, + ); + + donations = [...donations, ...response.donations]; + + // Check if we need to fetch more + if (response.donations.length < limit) { + hasMore = false; + } else { + offset += limit; + } + } // Filter out invalid donations and map the project metadata from application metadata (solution for canonical projects in indexer v2) - const validDonations = response.donations.reduce( + const validDonations = donations.reduce( (validDonations, donation) => { if (donation.round.strategyName !== "allov2.DirectAllocationStrategy") { if (donation.application?.project) { diff --git a/packages/data-layer/src/queries.ts b/packages/data-layer/src/queries.ts index 652bc98cf..6ddcf922b 100644 --- a/packages/data-layer/src/queries.ts +++ b/packages/data-layer/src/queries.ts @@ -773,8 +773,15 @@ export const getRoundForExplorer = gql` `; export const getDonationsByDonorAddress = gql` - query getDonationsByDonorAddress($address: String!, $chainIds: [Int!]!) { + query getDonationsByDonorAddress( + $address: String! + $chainIds: [Int!]! + $limit: Int = 200 + $offset: Int = 0 + ) { donations( + limit: $limit + offset: $offset where: { chainId: { _in: $chainIds }, donorAddress: { _eq: $address } } ) { id