Repository: appsmithorg/appsmith
File: app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java (Java)

Code before:

        // Fetch all the actions which exist in this page.
        Flux<Executable> creatorContextExecutablesFlux =
                this.getAllExecutablesByCreatorIdFlux(creatorId, creatorType).cache();

        // Before we update the actions, fetch all the actions which are currently set to execute on load.
        Mono<List<Executable>> existingOnLoadExecutablesMono = creatorContextExecutablesFlux
                .flatMap(executable -> {
                    if (RunBehaviourEnum.ON_PAGE_LOAD.equals(executable.getRunBehaviour())) {
                        return Mono.just(executable);
                    }
                    return Mono.empty();
                })
                .collectList();

        return existingOnLoadExecutablesMono
                .zipWith(creatorContextExecutablesFlux.collectList())
                .flatMap(tuple -> featureFlagService
                        .check(FeatureFlagEnum.release_reactive_actions_enabled)
                        .flatMap(isReactiveActionsEnabled -> {
                            List<Executable> existingOnLoadExecutables = tuple.getT1();
                            List<Executable> creatorContextExecutables = tuple.getT2();

                            // There are no actions in this page. No need to proceed further since no actions would get
                            // updated
                            if (creatorContextExecutables.isNullOrEmpty()) {
                                return Mono.just(FALSE);
                            }

                            // No actions require an update if no actions have been found as page load actions as well
                            // as
                            // existing on load page actions are empty
                            if (existingOnLoadExecutables.isNullOrEmpty()
                                    && (onLoadExecutables == null || onLoadExecutables.isNullOrEmpty())) {
                                return Mono.just(FALSE);
                            }

                            // Extract names of existing page load actions and new page load actions for quick lookup.
                            Set<String> existingOnLoadExecutableNames = existingOnLoadExecutables.stream()
                                    .map(Executable::getUserExecutableName)
                                    .collect(Collectors.toSet());

                            Set<String> newOnLoadExecutableNames = onLoadExecutables.stream()
                                    .map(Executable::getUserExecutableName)
                                    .collect(Collectors.toSet());

                            // Calculate the actions which would need to be updated from execute on load TRUE to FALSE.
                            Set<String> turnedOffExecutableNames = new HashSet<>();
                            turnedOffExecutableNames.addAll(existingOnLoadExecutableNames);
                            turnedOffExecutableNames.removeAll(newOnLoadExecutableNames);


Review comment (refactor):
Can you please use `com.appsmith.server.helpers.CollectionUtils.isNullOrEmpty()` instead?

Code after:
        List<Executable> toUpdateExecutables = new ArrayList<>();

        // Fetch all the actions which exist in this page.
        Flux<Executable> creatorContextExecutablesFlux =
                this.getAllExecutablesByCreatorIdFlux(creatorId, creatorType).cache();

        // Before we update the actions, fetch all the actions which are currently set to execute on load.
        Mono<List<Executable>> existingOnLoadExecutablesMono = creatorContextExecutablesFlux
                .flatMap(executable -> {
                    if (RunBehaviourEnum.ON_PAGE_LOAD.equals(executable.getRunBehaviour())) {
                        return Mono.just(executable);
                    }
                    return Mono.empty();
                })
                .collectList();

        return existingOnLoadExecutablesMono
                .zipWith(creatorContextExecutablesFlux.collectList())
                .flatMap(tuple -> featureFlagService
                        .check(FeatureFlagEnum.release_reactive_actions_enabled)
                        .flatMap(isReactiveActionsEnabled -> {
                            List<Executable> existingOnLoadExecutables = tuple.getT1();
                            List<Executable> creatorContextExecutables = tuple.getT2();

                            // There are no actions in this page. No need to proceed further since no actions would get
                            // updated
                            if (CollectionUtils.isNullOrEmpty(creatorContextExecutables)) {
                                return Mono.just(FALSE);
                            }

                            // No actions require an update if no actions have been found as page load actions as well
                            // as
                            // existing on load page actions are empty
                            if (CollectionUtils.isNullOrEmpty(existingOnLoadExecutables)
                                    && (onLoadExecutables == null
                                            || CollectionUtils.isNullOrEmpty(onLoadExecutables))) {
                                return Mono.just(FALSE);
                            }

                            // Extract names of existing page load actions and new page load actions for quick lookup.
                            Set<String> existingOnLoadExecutableNames = existingOnLoadExecutables.stream()
                                    .map(Executable::getUserExecutableName)
                                    .collect(Collectors.toSet());

                            Set<String> newOnLoadExecutableNames = onLoadExecutables.stream()
                                    .map(Executable::getUserExecutableName)
                                    .collect(Collectors.toSet());

                            // Calculate the actions which would need to be updated from execute on load TRUE to FALSE.
                            Set<String> turnedOffExecutableNames = new HashSet<>();
                            turnedOffExecutableNames.addAll(existingOnLoadExecutableNames);