Skip to content

Commit 338d04f

Browse files
authored
fix: manager applications query with pagination (#3810)
1 parent 156f50e commit 338d04f

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,31 @@ export class DataLayer {
783783
chainId: number;
784784
roundId: string;
785785
}): Promise<ProjectApplicationForManager[]> {
786-
const response: { applications: ProjectApplicationForManager[] } =
787-
await request(this.gsIndexerEndpoint, getApplicationsForManager, args);
786+
const PAGE_SIZE = 200; // You can adjust this value based on your needs
787+
let allApplications: ProjectApplicationForManager[] = [];
788+
let offset = 0;
789+
let hasMore = true;
790+
791+
while (hasMore) {
792+
const response: { applications: ProjectApplicationForManager[] } =
793+
await request(this.gsIndexerEndpoint, getApplicationsForManager, {
794+
...args,
795+
limit: PAGE_SIZE,
796+
offset,
797+
});
798+
799+
const applications = response.applications;
800+
allApplications = [...allApplications, ...applications];
801+
802+
// If we got fewer results than the page size, we've reached the end
803+
if (applications.length < PAGE_SIZE) {
804+
hasMore = false;
805+
} else {
806+
offset += PAGE_SIZE;
807+
}
808+
}
788809

789-
return response.applications;
810+
return allApplications;
790811
}
791812

792813
async getDonationsByDonorAddress(args: {

packages/data-layer/src/queries.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,16 @@ export const getApprovedApplicationsByProjectIds = gql`
244244
`;
245245

246246
export const getApplicationsForManager = gql`
247-
query getApplicationsForManager($chainId: Int!, $roundId: String!) {
247+
query getApplicationsForManager(
248+
$chainId: Int!
249+
$roundId: String!
250+
$limit: Int!
251+
$offset: Int!
252+
) {
248253
applications(
249254
where: { roundId: { _eq: $roundId }, chainId: { _eq: $chainId } }
255+
limit: $limit
256+
offset: $offset
250257
) {
251258
id
252259
projectId

0 commit comments

Comments
 (0)