objectcomputing / check-ins

Other
7 stars 7 forks source link

Unnecessary reactive code #2410

Closed sdelamo closed 4 weeks ago

sdelamo commented 1 month ago

We use reactive code in controllers where it is unnecessary:

@Controller("/services/today")
@ExecuteOn(TaskExecutors.BLOCKING)
@Secured(SecurityRule.IS_AUTHENTICATED)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Tag(name = "Today")
public class TodayController {

    private final TodayServices todayServices;

    public TodayController(TodayServices todayServices) {
        this.todayServices = todayServices;
    }

    @Get()
    public Mono<HttpResponse<TodayResponseDTO>> getTodaysEvents() {
        return Mono.fromCallable(todayServices::getTodaysEvents)
                .map(HttpResponse::ok);
    }
}

The previous controller already offloads to the IO thread pool: @ExecuteOn(TaskExecutors.BLOCKING)

We could rewrite the getTodayEvents as

    @Get
    TodayResponseDTO getTodaysEvents() {
        return todayServices.getTodaysEvents();
    }