Skip to content

Commit 376bc45

Browse files
authored
fix: donations query pagination (#3823)
1 parent f7d528c commit 376bc45

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

packages/data-layer/src/data-layer.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -816,17 +816,30 @@ export class DataLayer {
816816
chainIds: number[];
817817
}): Promise<Contribution[]> {
818818
const { address, chainIds } = args;
819-
const response: { donations: Contribution[] } = await request(
820-
this.gsIndexerEndpoint,
821-
getDonationsByDonorAddress,
822-
{
823-
address: getAddress(address),
824-
chainIds,
825-
},
826-
);
819+
let offset = 0;
820+
let hasMore = true;
821+
const limit = 200;
822+
let donations: Contribution[] = [];
823+
824+
while (hasMore) {
825+
const response: { donations: Contribution[] } = await request(
826+
this.gsIndexerEndpoint,
827+
getDonationsByDonorAddress,
828+
{ address: getAddress(address), chainIds, limit, offset },
829+
);
830+
831+
donations = [...donations, ...response.donations];
832+
833+
// Check if we need to fetch more
834+
if (response.donations.length < limit) {
835+
hasMore = false;
836+
} else {
837+
offset += limit;
838+
}
839+
}
827840

828841
// Filter out invalid donations and map the project metadata from application metadata (solution for canonical projects in indexer v2)
829-
const validDonations = response.donations.reduce<Contribution[]>(
842+
const validDonations = donations.reduce<Contribution[]>(
830843
(validDonations, donation) => {
831844
if (donation.round.strategyName !== "allov2.DirectAllocationStrategy") {
832845
if (donation.application?.project) {

packages/data-layer/src/queries.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,15 @@ export const getRoundForExplorer = gql`
773773
`;
774774

775775
export const getDonationsByDonorAddress = gql`
776-
query getDonationsByDonorAddress($address: String!, $chainIds: [Int!]!) {
776+
query getDonationsByDonorAddress(
777+
$address: String!
778+
$chainIds: [Int!]!
779+
$limit: Int = 200
780+
$offset: Int = 0
781+
) {
777782
donations(
783+
limit: $limit
784+
offset: $offset
778785
where: { chainId: { _in: $chainIds }, donorAddress: { _eq: $address } }
779786
) {
780787
id

0 commit comments

Comments
 (0)