Open julian9499 opened 8 months ago
Ordertaskscheduler causes a high database load every 30 minutes. The findall method call iterates over the entire database:
@Scheduled(fixedRate = CLEAN_UP_TASK_INTERVAL_SECONDS * MILLISEC_IN_SEC) public void cleanUpTask() { orderService.getAllOrders().forEach(order -> { if (order.getCreatedAt().isBefore(LocalDateTime.now().minusMinutes(CLEAN_UP_INTERVAL))) { OrderStatus[] cleanUpStatus = new OrderStatus[]{OrderStatus.ANONYMOUS, OrderStatus.ASSIGNED}; if (ArrayUtils.contains(cleanUpStatus, order.getStatus())) { log.info("Order " + order.getPublicReference() + ": Order has been deleted!"); orderService.delete(order); } } }); }
Ordertaskscheduler causes a high database load every 30 minutes. The findall method call iterates over the entire database: