Skip to content

Commit

Permalink
[sitecore-jss-nextjs] Reduce the amount of Edge API calls during fetc…
Browse files Browse the repository at this point in the history
…h `getStaticPaths` (#1612)

* change sitemap service pageSize, serialize getStaticPaths

* update changelog
  • Loading branch information
addy-pathania authored Sep 15, 2023
1 parent d1f7455 commit fb32a11
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Our versioning strategy is as follows:
* `[sitecore-jss-react]` Fetch Data for FEaaS Components as part of Component SSR/SSG ([#1586](https://github.com/Sitecore/jss/pull/1590))
* `[sitecore-jss-dev-tools]` `[templates/nextjs]` `[templates/react]` Introduce "components" configuration for ComponentBuilder ([#1598](https://github.com/Sitecore/jss/pull/1598))
* `[sitecore-jss-react]` `[sitecore-jss-nextjs]` Component level data fetching(SSR/SSG) for BYOC ([#1610](https://github.com/Sitecore/jss/pull/1610))
* `[sitecore-jss-nextjs]` Reduce the amount of Edge API calls during fetch getStaticPaths ([#1612](https://github.com/Sitecore/jss/pull/1612))

### 🧹 Chores

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
$language: String!
$includedPaths: [String]
$excludedPaths: [String]
$pageSize: Int = 10
$pageSize: Int = 100
$after: String
) {
site {
Expand Down Expand Up @@ -86,7 +86,7 @@ interface SiteRouteQueryVariables {
/** common variable for all GraphQL queries
* it will be used for every type of query to regulate result batch size
* Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
* @default 10
* @default 100
*/
pageSize?: number;
}
Expand Down Expand Up @@ -223,21 +223,24 @@ export abstract class BaseGraphQLSitemapService {
formatStaticPath: (path: string[], language: string) => StaticPath
) {
const paths = new Array<StaticPath>();
await Promise.all(
languages.map(async (language) => {
if (language === '') {
throw new RangeError(languageEmptyError);
}
debug.sitemap('fetching sitemap data for %s %s', language, siteName);
const results = await this.fetchLanguageSitePaths(language, siteName);
const transformedPaths = await this.transformLanguageSitePaths(
results,
formatStaticPath,
language
);
paths.push(...transformedPaths);
})
);

for (const language of languages) {
if (language === '') {
throw new RangeError(languageEmptyError);
}

debug.sitemap('fetching sitemap data for %s %s', language, siteName);

const results = await this.fetchLanguageSitePaths(language, siteName);
const transformedPaths = await this.transformLanguageSitePaths(
results,
formatStaticPath,
language
);

paths.push(...transformedPaths);
}

return paths;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ describe('GraphQLSitemapService', () => {
.post(
'/',
(body) =>
body.query.indexOf('$pageSize: Int = 10') > 0 && body.variables.pageSize === undefined
body.query.indexOf('$pageSize: Int = 100') > 0 &&
body.variables.pageSize === undefined
)
.reply(200, sitemapDefaultQueryResult);

Expand Down

0 comments on commit fb32a11

Please sign in to comment.