diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/AnalyticsEvents.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/AnalyticsEvents.java index b5b006f413..8e981b6507 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/AnalyticsEvents.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/AnalyticsEvents.java @@ -45,6 +45,7 @@ public enum AnalyticsEvents { GIT_LIST_BRANCH, GIT_RESET, GIT_STATUS, + GIT_STATUS_WITHOUT_FETCH, GIT_COMMIT_HISTORY, GIT_CLONE, GIT_CHECKOUT, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java index de5573640f..6a7e6ff8ce 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java @@ -1740,7 +1740,7 @@ public class GitServiceCEImpl implements GitServiceCE { 1. Copy resources from DB to local repo 2. Fetch the current status from local repo */ - Mono currUserMono = sessionUserService.getCurrentUser().cache(); + Mono currUserMono = sessionUserService.getCurrentUser(); Mono statusMono = getGitApplicationMetadata(defaultApplicationId) .flatMap(gitApplicationMetadata -> { Mono> applicationJsonTuple = branchedAppMono @@ -1843,17 +1843,24 @@ public class GitServiceCEImpl implements GitServiceCE { GitStatusDTO gitStatusDTO = objects.getT2().getT1(); User currentUser = objects.getT2().getT2(); Application app = objects.getT2().getT3(); - return sendAnalyticsEvent(elapsedTime, gitStatusDTO, currentUser, app); + String flowName; + if (compareRemote) { + flowName = AnalyticsEvents.GIT_STATUS.getEventName(); + } else { + flowName = AnalyticsEvents.GIT_STATUS_WITHOUT_FETCH.getEventName(); + } + return sendUnitExecutionTimeAnalyticsEvent(flowName, elapsedTime, currentUser, app) + .thenReturn(gitStatusDTO); }) .subscribe(sink::success, sink::error, null, sink.currentContext()); }); } - private Mono sendAnalyticsEvent( - Long elapsedTime, GitStatusDTO gitStatusDTO, User currentUser, Application app) { + private Mono sendUnitExecutionTimeAnalyticsEvent( + String flowName, Long elapsedTime, User currentUser, Application app) { final Map data = Map.of( FieldName.FLOW_NAME, - AnalyticsEvents.GIT_STATUS.getEventName(), + flowName, FieldName.APPLICATION_ID, app.getGitApplicationMetadata().getDefaultApplicationId(), "appId", @@ -1866,9 +1873,8 @@ public class GitServiceCEImpl implements GitServiceCE { app.getGitApplicationMetadata().getRemoteUrl(), "executionTime", elapsedTime); - return analyticsService - .sendEvent(AnalyticsEvents.UNIT_EXECUTION_TIME.getEventName(), currentUser.getUsername(), data) - .thenReturn(gitStatusDTO); + return analyticsService.sendEvent( + AnalyticsEvents.UNIT_EXECUTION_TIME.getEventName(), currentUser.getUsername(), data); } @Override @@ -1896,11 +1902,13 @@ public class GitServiceCEImpl implements GitServiceCE { } final String finalBranchName = branchName.replaceFirst("origin/", ""); - Mono statusMono = getGitApplicationMetadata(defaultApplicationId) + Mono applicationMono = applicationService + .findByBranchNameAndDefaultApplicationId( + finalBranchName, defaultApplicationId, applicationPermission.getEditPermission()) + .cache(); // caching as it'll be also used when sending analytics + Mono currUserMono = sessionUserService.getCurrentUser(); // will be used to send analytics event + Mono fetchRemoteStatusMono = getGitApplicationMetadata(defaultApplicationId) .flatMap(gitApplicationMetadata -> { - Mono applicationMono = applicationService.findByBranchNameAndDefaultApplicationId( - finalBranchName, defaultApplicationId, applicationPermission.getEditPermission()); - if (Boolean.TRUE.equals(isFileLock)) { // Add file lock to avoid sending wrong info on the status return redisUtils @@ -1952,10 +1960,21 @@ public class GitServiceCEImpl implements GitServiceCE { return Mono.error(new AppsmithException( AppsmithError.GIT_ACTION_FAILED, "status", error.getMessage())); }); + }) + .elapsed() + .zipWith(Mono.zip(currUserMono, applicationMono)) + .flatMap(objects -> { + Long elapsedTime = objects.getT1().getT1(); + BranchTrackingStatus branchTrackingStatus = objects.getT1().getT2(); + User currentUser = objects.getT2().getT1(); + Application app = objects.getT2().getT2(); + return sendUnitExecutionTimeAnalyticsEvent( + AnalyticsEvents.GIT_FETCH.getEventName(), elapsedTime, currentUser, app) + .thenReturn(branchTrackingStatus); }); return Mono.create(sink -> { - statusMono.subscribe(sink::success, sink::error, null, sink.currentContext()); + fetchRemoteStatusMono.subscribe(sink::success, sink::error, null, sink.currentContext()); }); }