Skip to content

Scheduled task for deleting order reservations causes high database load due to wrong findAll() call #460

Description

@julian9499

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);
                }
            }
        });
    }
    ```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions