Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
julian9499 opened this issue Dec 7, 2023 · 0 comments

Comments

@julian9499
Copy link
Contributor

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);
                }
            }
        });
    }
    ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant