-
Notifications
You must be signed in to change notification settings - Fork 211
MWPW-185513 load federal query index only if federal links are present #5271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stage
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -614,26 +614,29 @@ function processQueryIndexMap(link, domain) { | |
| return result; | ||
| } | ||
|
|
||
| async function loadQueryIndexes(prefix, onlyCurrentSite = false) { | ||
| async function loadQueryIndexes(prefix, onlyCurrentSite = false, links = []) { | ||
| const config = getConfig(); | ||
| const queryIndexSuffix = window.location.host.includes(`${SLD}.page`) ? '-preview' : ''; | ||
|
|
||
| if (links.length && links.some((link) => link.includes('/federal/')) && !queryIndexes.federal) { | ||
| queryIndexes.federal = processQueryIndexMap( | ||
| `${getFederatedContentRoot()}${prefix}/federal/assets/lingo/query-index${queryIndexSuffix}.json`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vhargrave Currently there are no lingo query indexes created for the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sunilkamat it's for when we need it later this year exactly. It's probably not very necessary for BACOM. |
||
| getFederatedContentRoot().replace('https://', ''), | ||
| ); | ||
| queryIndexes.federal.domains.push(window.location.hostname); | ||
| } | ||
| if (lingoSiteMapping || isLoadingQueryIndexes) return; | ||
| isLoadingQueryIndexes = true; | ||
|
|
||
| const origin = config.origin || window.location.origin; | ||
| const contentRoot = config.contentRoot ?? ''; | ||
| const regionalContentRoot = `${origin}${prefix}${contentRoot}`; | ||
| const siteId = config.uniqueSiteId ?? ''; | ||
| const queryIndexSuffix = window.location.host.includes(`${SLD}.page`) ? '-preview' : ''; | ||
|
|
||
| queryIndexes[siteId] = processQueryIndexMap( | ||
| `${regionalContentRoot}/assets/lingo/query-index${queryIndexSuffix}.json`, | ||
| window.location.hostname, | ||
| ); | ||
| queryIndexes.federal = processQueryIndexMap( | ||
| `${getFederatedContentRoot()}${prefix}/federal/assets/lingo/query-index${queryIndexSuffix}.json`, | ||
| getFederatedContentRoot().replace('https://', ''), | ||
| ); | ||
|
|
||
| if (onlyCurrentSite) { | ||
| lingoSiteMapping = Promise.resolve(lingoSiteMappingLoaded = true); | ||
|
|
@@ -730,9 +733,7 @@ function localizeLinkCore( | |
| && ((locale.base && !path.includes('/fragments/')) | ||
| || (!!locale.regions && path.includes('/fragments/') && aTag.dataset.mepLingo === 'true'))) { | ||
| return (async () => { | ||
| if (!(lingoSiteMapping || isLoadingQueryIndexes)) { | ||
| loadQueryIndexes(prefix); | ||
| } | ||
| loadQueryIndexes(prefix, false, [href]); | ||
| if (!(queryIndexes[siteId]?.requestResolved || lingoSiteMappingLoaded)) { | ||
| await Promise.all([queryIndexes[siteId]?.pathsRequest, lingoSiteMapping].filter(Boolean)); | ||
| } | ||
|
|
@@ -2125,17 +2126,16 @@ async function processSection(section, config, isDoc, lcpSectionId) { | |
| return section.blocks; | ||
| } | ||
|
|
||
| function loadLingoIndexes() { | ||
| function loadLingoIndexes(area = document) { | ||
| const config = getConfig(); | ||
| const { locale } = config || {}; | ||
|
|
||
| if (locale?.base) { | ||
| loadQueryIndexes(config.locale.prefix); | ||
| loadQueryIndexes(config.locale.prefix, false, [...area.querySelectorAll('.section a')].map((a) => a.href).filter(Boolean)); | ||
| return; | ||
| } | ||
| const prefix = getMepLingoPrefix(); | ||
| if (prefix) { | ||
| loadQueryIndexes(prefix, true); | ||
| loadQueryIndexes(prefix, true, [...area.querySelectorAll('.section a')].map((a) => a.href).filter(Boolean)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2159,11 +2159,12 @@ export async function loadArea(area = document) { | |
| await decorateDocumentExtras(); | ||
| initModalEventListener(); | ||
| } | ||
| if (isLingoActive) loadLingoIndexes(); | ||
|
|
||
| const htmlSections = [...area.querySelectorAll(isDoc ? 'body > main > div' : ':scope > div')]; | ||
| htmlSections.forEach((section) => { section.className = 'section'; section.dataset.status = 'pending'; }); | ||
|
|
||
| if (isLingoActive) loadLingoIndexes(area); | ||
|
|
||
| const areaBlocks = []; | ||
| let lcpSectionId = null; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: No need to check for length,
somewill return false if array is empty