From 843cfeecfc72c2d1d6c99c84576cae93b3d98439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Csneha122=E2=80=9D?= <“sneha@appsmith.com”> Date: Wed, 11 Sep 2024 13:24:15 +0530 Subject: [PATCH 1/2] fix: fixed page data DB call getting called twice --- .../ce/ConsolidatedAPIServiceCEImpl.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java index 2cc9776c4744..f08e4d61851e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java @@ -225,26 +225,22 @@ public Mono getConsolidatedInfoForPageLoad( 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 -> + // 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( From d36df4cb300653a51d10a09b3315aaa114b68034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Csneha122=E2=80=9D?= <“sneha@appsmith.com”> Date: Wed, 11 Sep 2024 14:51:08 +0530 Subject: [PATCH 2/2] fix: code review changes addressed --- .../services/ce/ConsolidatedAPIServiceCEImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java index f08e4d61851e..1f046c8ba290 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ConsolidatedAPIServiceCEImpl.java @@ -201,6 +201,9 @@ public Mono getConsolidatedInfoForPageLoad( boolean isViewMode = ApplicationMode.PUBLISHED.equals(mode); /* Fetch default application id if not provided */ + if (isBlank(basePageId)) { + return Mono.when(fetches).thenReturn(consolidatedAPIResponseDTO); + } Mono branchedApplicationMonoCached; Mono baseApplicationIdMono = Mono.just(""); if (isViewMode) { @@ -215,12 +218,9 @@ public Mono getConsolidatedInfoForPageLoad( .tap(Micrometer.observation(observationRegistry)) .cache(); - Mono branchedPageMonoCached = Mono.empty(); - if (!isBlank(basePageId)) { - branchedPageMonoCached = newPageService - .findByBranchNameAndBasePageIdAndApplicationMode(branchName, basePageId, mode) - .cache(); - } + Mono branchedPageMonoCached = newPageService + .findByBranchNameAndBasePageIdAndApplicationMode(branchName, basePageId, mode) + .cache(); branchedApplicationMonoCached = baseApplicationIdMono.flatMap(cachedBaseApplicationId -> { if (!StringUtils.hasText(cachedBaseApplicationId)) {