Skip to content

Commit

Permalink
Fix #84 Max Included Items limits
Browse files Browse the repository at this point in the history
  • Loading branch information
ComLock committed Mar 7, 2024
1 parent b4c6cbb commit 49a0cd9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/main/resources/guillotine/resolvers/urlset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
import {
DEFAULT_PRIORITY,
DEFAULT_UPDATE_PERIOD,
MAX_ITEMS_LIMIT,
} from '/lib/app-sitemapxml/constants';
import {queryForSitemapContent} from '/lib/app-sitemapxml/queryForSitemapContent';
import {URLSET_FIELD_NAME} from '/guillotine/constants';
Expand Down Expand Up @@ -78,9 +77,6 @@ export const urlset = (graphQL: GraphQL): Resolver<
const {
count = maxItemsInt
} = args;
const limitedCount = count < 0
? MAX_ITEMS_LIMIT
: Math.min(count, MAX_ITEMS_LIMIT);

const {
branch,
Expand All @@ -104,7 +100,7 @@ export const urlset = (graphQL: GraphQL): Resolver<
priority,
result
} = queryForSitemapContent({
count: limitedCount,
count,
site,
siteConfig
});
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/lib/app-sitemapxml/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export const DEFAULT_UPDATE_PERIOD: tChangeFreq = 'monthly';

// https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
// Container for a set of up to 50,000 document elements. This is the root element of the XML file.
export const MAX_ITEMS_LIMIT: number = 50000;
export const MAX_ITEMS_LIMIT = 50000;

export const ES_MAX_ITEMS_LIMIT = 10000;
15 changes: 13 additions & 2 deletions src/main/resources/lib/app-sitemapxml/queryForSitemapContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
DEFAULT_PRIORITY,
DEFAULT_UPDATE_PERIOD,
ES_MAX_ITEMS_LIMIT,
MAX_ITEMS_LIMIT
} from '/lib/app-sitemapxml/constants';

Expand Down Expand Up @@ -134,8 +135,18 @@ export function queryForSitemapContent({

const mustNot: QueryDsl[] = blockRobotsDslArray.concat(ignoreDslArray);

const countBetweenZeroAndMaxItemsLimit = (count >= 0 && count <= MAX_ITEMS_LIMIT)
? count
: MAX_ITEMS_LIMIT;
DEBUG && log.debug('countBetweenZeroAndMaxItemsLimit: %s', toStr(countBetweenZeroAndMaxItemsLimit));

const countWithinElasticSearchMaxItemsLimitOrMinusOne = (countBetweenZeroAndMaxItemsLimit <= ES_MAX_ITEMS_LIMIT)
? countBetweenZeroAndMaxItemsLimit
: -1;
DEBUG && log.debug('countWithinElasticSearchMaxItemsLimitOrMinusOne: %s', toStr(countWithinElasticSearchMaxItemsLimitOrMinusOne));

const nodeQueryParams = {
count: -1,
count: countWithinElasticSearchMaxItemsLimitOrMinusOne,
query: {
boolean: {
must,
Expand All @@ -154,7 +165,7 @@ export function queryForSitemapContent({
}
DEBUG && log.debug('nodeQueryRes.total: %s', nodeQueryRes.total);

const stopBefore = Math.min(nodeQueryRes.hits.length, count, MAX_ITEMS_LIMIT);
const stopBefore = Math.min(nodeQueryRes.hits.length, countBetweenZeroAndMaxItemsLimit);
DEBUG && log.debug('stopBefore: %s', stopBefore);

const contents: {
Expand Down
8 changes: 1 addition & 7 deletions src/main/resources/site/controllers/sitemap/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '/lib/xp/portal';
// @ts-expect-error No types yet.
import {render} from '/lib/xslt';
import {MAX_ITEMS_LIMIT} from '/lib/app-sitemapxml/constants';
import {queryForSitemapContent} from '/lib/app-sitemapxml/queryForSitemapContent';


Expand Down Expand Up @@ -57,17 +56,12 @@ export function get(request: Request<{
overrideDomain = '',
} = siteConfig || {}; // Handle null (aka no config)

const maxItemsInt = Math.min(
MAX_ITEMS_LIMIT,
parseInt(maxItems as string, 10)
);

const {
changefreq,
priority,
result
} = queryForSitemapContent({
count: maxItemsInt,
count: parseInt(maxItems as string, 10),

Check warning on line 64 in src/main/resources/site/controllers/sitemap/sitemap.ts

View check run for this annotation

Codecov / codecov/patch

src/main/resources/site/controllers/sitemap/sitemap.ts#L64

Added line #L64 was not covered by tests
site,
siteConfig,
});
Expand Down

0 comments on commit 49a0cd9

Please sign in to comment.