Skip to content
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

fix: fixed page data DB call getting called twice #36247

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public Mono<ConsolidatedAPIResponseDTO> getConsolidatedInfoForPageLoad(
boolean isViewMode = ApplicationMode.PUBLISHED.equals(mode);

/* Fetch default application id if not provided */
if (isBlank(basePageId)) {
return Mono.when(fetches).thenReturn(consolidatedAPIResponseDTO);
}
Mono<Application> branchedApplicationMonoCached;
Mono<String> baseApplicationIdMono = Mono.just("");
if (isViewMode) {
Expand All @@ -215,36 +218,29 @@ public Mono<ConsolidatedAPIResponseDTO> getConsolidatedInfoForPageLoad(
.tap(Micrometer.observation(observationRegistry))
.cache();

Mono<NewPage> branchedPageMonoCached = Mono.empty();
if (!isBlank(basePageId)) {
branchedPageMonoCached = newPageService
.findByBranchNameAndBasePageIdAndApplicationMode(branchName, basePageId, mode)
.cache();
}
Mono<NewPage> branchedPageMonoCached = newPageService
.findByBranchNameAndBasePageIdAndApplicationMode(branchName, basePageId, mode)
.cache();

branchedApplicationMonoCached = baseApplicationIdMono.flatMap(cachedBaseApplicationId -> {
if (!StringUtils.hasText(cachedBaseApplicationId)) {
// Handle empty or null baseApplicationId
return newPageService
.findByBranchNameAndBasePageIdAndApplicationMode(branchName, basePageId, mode)
.flatMap(branchedPage ->
// Use the application ID to find the complete application details.
applicationService
.findByBranchedApplicationIdAndApplicationMode(
branchedPage.getApplicationId(), mode)
.flatMap(application -> {
if (isViewMode) {
// Update the cache with the new application’s base ID for future
// queries.
return cacheableRepositoryHelper
.fetchBaseApplicationId(basePageId, application.getBaseId())
.thenReturn(application)
.name(getQualifiedSpanName(
APPLICATION_ID_UPDATE_REDIS_SPAN, mode))
.tap(Micrometer.observation(observationRegistry));
}
return Mono.just(application);
}));
return branchedPageMonoCached.flatMap(branchedPage ->
sneha122 marked this conversation as resolved.
Show resolved Hide resolved
sneha122 marked this conversation as resolved.
Show resolved Hide resolved
// Use the application ID to find the complete application details.
applicationService
.findByBranchedApplicationIdAndApplicationMode(branchedPage.getApplicationId(), mode)
.flatMap(application -> {
if (isViewMode) {
// Update the cache with the new application’s base ID for future
// queries.
return cacheableRepositoryHelper
.fetchBaseApplicationId(basePageId, application.getBaseId())
.thenReturn(application)
.name(getQualifiedSpanName(APPLICATION_ID_UPDATE_REDIS_SPAN, mode))
.tap(Micrometer.observation(observationRegistry));
}
return Mono.just(application);
}));
} else {
// Handle non-empty baseApplicationId
return applicationService.findByBaseIdBranchNameAndApplicationMode(
Expand Down
Loading