Skip to content

Commit 6f5435b

Browse files
committed
refactor: streamline fetching of GitHub sponsors by combining sponsorships and donations queries
1 parent c493a8d commit 6f5435b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

apps/site/next-data/generators/supportersData.mjs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ async function fetchGithubSponsorsData() {
119119
return [];
120120
}
121121

122-
const sponsors = [];
122+
const [sponsorships, donations] = await Promise.all([
123+
fetchSponsorshipsQuery(),
124+
fetchDonationsQuery(),
125+
]);
126+
127+
return [...sponsorships, ...donations];
128+
}
123129

124-
// Fetch sponsorship pages
130+
async function fetchSponsorshipsQuery() {
131+
const sponsors = [];
125132
let cursor = null;
126133

127134
while (true) {
@@ -156,6 +163,10 @@ async function fetchGithubSponsorsData() {
156163
cursor = pageInfo.endCursor;
157164
}
158165

166+
return sponsors;
167+
}
168+
169+
async function fetchDonationsQuery() {
159170
const data = await graphql(DONATIONS_QUERY);
160171

161172
if (data.errors) {
@@ -164,11 +175,11 @@ async function fetchGithubSponsorsData() {
164175

165176
const nodeRes = data.data.organization?.sponsorsActivities;
166177
if (!nodeRes) {
167-
return sponsors;
178+
return [];
168179
}
169180

170181
const { nodes } = nodeRes;
171-
const mapped = nodes.map(n => {
182+
return nodes.map(n => {
172183
const s = n.sponsor || n.sponsorEntity || n.sponsorEntity; // support different field names
173184
return {
174185
name: s?.name || s?.login || null,
@@ -177,10 +188,6 @@ async function fetchGithubSponsorsData() {
177188
source: 'github',
178189
};
179190
});
180-
181-
sponsors.push(...mapped);
182-
183-
return sponsors;
184191
}
185192

186193
const graphql = async (query, variables = {}) => {

0 commit comments

Comments
 (0)