From 2f56df40311ab6cfaa31500e0b6726ec38ab1ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 8 Oct 2024 12:41:16 +0200 Subject: [PATCH] fix(jdbc): always include deleted the the logs and metrics queries Even if not needed to be sure we use the correct index. --- .../jdbc/repository/AbstractJdbcLogRepository.java | 5 ++++- .../jdbc/repository/AbstractJdbcMetricRepository.java | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java index c172380178..4ac4391e90 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java +++ b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java @@ -350,7 +350,10 @@ public Integer purge(Execution execution) { DSLContext context = DSL.using(configuration); return context.delete(this.jdbcRepository.getTable()) - .where(field("execution_id", String.class).eq(execution.getId())) + // The deleted field is not used, so ti will always be false. + // We add it here to be sure to use the correct index. + .where(field("deleted", Boolean.class).eq(false)) + .and(field("execution_id", String.class).eq(execution.getId())) .execute(); }); } diff --git a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java index d920a0ebe0..1ed0d7438a 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java +++ b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java @@ -150,7 +150,10 @@ public Integer purge(Execution execution) { DSLContext context = DSL.using(configuration); return context.delete(this.jdbcRepository.getTable()) - .where(field("execution_id", String.class).eq(execution.getId())) + // The deleted field is not used, so ti will always be false. + // We add it here to be sure to use the correct index. + .where(field("deleted", Boolean.class).eq(false)) + .and(field("execution_id", String.class).eq(execution.getId())) .execute(); }); } @@ -168,8 +171,7 @@ private List queryDistinct(String tenantId, Condition condition, String .getDslContextWrapper() .transactionResult(configuration -> { DSLContext context = DSL.using(configuration); - SelectConditionStep> select = DSL - .using(configuration) + SelectConditionStep> select = context .selectDistinct(field(field)) .from(this.jdbcRepository.getTable()) .where(this.defaultFilter(tenantId)); @@ -185,8 +187,7 @@ private ArrayListTotal query(String tenantId, Condition condition, .getDslContextWrapper() .transactionResult(configuration -> { DSLContext context = DSL.using(configuration); - SelectConditionStep> select = DSL - .using(configuration) + SelectConditionStep> select = context .select(field("value")) .from(this.jdbcRepository.getTable()) .where(this.defaultFilter(tenantId));