Skip to content

Commit

Permalink
chore: include hotfix-18364 (#26149)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsolistorres committed Sep 17, 2023
1 parent d8b4665 commit ddede47
Showing 1 changed file with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,42 @@ private void initializeActiveVanityURLsCacheBySiteAndLanguage(final String siteI
(siteId, languageId, includeSystemHost);
}
} catch (final Exception e) {
throw new DotRuntimeException("Error searching and populating the Vanity URL Cache", e);
throw new DotRuntimeException(String.format("Error searching and populating the Vanity URL from DB for " +
"Site ID '%s', language ID = '%s': %s", siteId, languageId, e.getMessage()), e);
}
} // initializeActiveVanityURLsCacheBySiteAndLanguage.

/**
* Searches for all Vanity URLs for a given Site in the system <b>without loading data into any of the Vanity URL
* Cache Regions</b>. This initialization routine will also add Vanity URLs located under System Host.
*
* @param siteId The ID of the Site whose Vanity URLs will be retrieved.
* @param languageId The ID of the language for the Vanity URLs.
*
* @return A list of Vanity URLs read from the data source.
*/
private List<CachedVanityUrl> getActiveVanityURLsNoCacheBySiteAndLanguage(final String siteId, final Long languageId) {
final boolean includeSystemHost = Boolean.TRUE;
try {
final List<Contentlet> contentResults = searchAndPopulate(siteId, languageId, includeSystemHost);
final List<VanityUrl> vanityUrls = contentResults.stream()
.map(this::getVanityUrlFromContentlet)
.sorted(Comparator.comparing(VanityUrl::getOrder))
.collect(toImmutableList());
final List<CachedVanityUrl> cachedVanityUrls = new ArrayList<>();
if (UtilMethods.isSet(vanityUrls)) {
// Simulate Vanity URLs coming from cache
for (final VanityUrl vanityUrl : vanityUrls) {
cachedVanityUrls.add(new CachedVanityUrl(vanityUrl));
}
}
return cachedVanityUrls;
} catch (final Exception e) {
throw new DotRuntimeException(String.format("Error searching and populating the Vanity URL from DB for " +
"Site ID '%s', language ID = '%s': %s", siteId, languageId, e.getMessage()), e);
}
}

/**
* Executes a SQL query that will return all the Vanity URLs that belong to a specific Site. This method moved from
* using the ES index to using a SQL query in order to avoid situations where the index was not fully updated when
Expand All @@ -151,7 +183,8 @@ private List<Contentlet> searchAndPopulate(final String siteId, final Long langu
List<Contentlet> contentlets = new ArrayList<>();
final StringBuilder query = new StringBuilder();
query.append("SELECT cvi.live_inode FROM contentlet c ");
query.append("INNER JOIN identifier i ON c.identifier = i.id AND i.host_inode ");
//c.text2 is the Site Field for Vanity URL Content Type
query.append("INNER JOIN identifier i ON c.identifier = i.id AND c.text2 ");
if (includeSystemHost) {
query.append("IN ('" + Host.SYSTEM_HOST + "', ?) ");
} else {
Expand Down Expand Up @@ -447,6 +480,12 @@ private CachedVanityUrl searchLiveCachedVanityUrlBySiteAndLanguage(final String
cachedVanityUrls =
this.getVanityUrlBySiteAndLanguageFromCache
(siteId, languageId,true);

if (!UtilMethods.isSet(cachedVanityUrls)) {
// If this point is reached, there's probably an issue with the Vanity URL Caches. So, just read
// directly from the data source WITHOUT reading or loading from any cache
cachedVanityUrls = this.getActiveVanityURLsNoCacheBySiteAndLanguage(siteId, languageId);
}
}
}
}
Expand Down Expand Up @@ -557,9 +596,11 @@ private void cleanCurrentVanityUrlsPerSite(final SiteLanguageKey siteLanguageKey
public void validateVanityUrl(final Contentlet contentlet) {

final User user = getUser(contentlet);
final Language language =
Language language =
APILocator.getLanguageAPI().getLanguage(user.getLanguageId());

language = (null == language ? APILocator.getLanguageAPI().getDefaultLanguage() : language);

// check fields
checkMissingField(contentlet, language, VanityUrlContentType.ACTION_FIELD_VAR);
checkMissingField(contentlet, language, VanityUrlContentType.URI_FIELD_VAR);
Expand Down

0 comments on commit ddede47

Please sign in to comment.