From 1d550cead7bcd82d22cf8d6724bebc2c8681780d Mon Sep 17 00:00:00 2001 From: Andrea Lamparelli Date: Wed, 4 Dec 2024 22:25:28 +0100 Subject: [PATCH] Fix calc_dataset_view join with label values Signed-off-by: Andrea Lamparelli --- .../tools/horreum/svc/TestServiceImpl.java | 6 ++--- .../src/main/resources/db/changeLog.xml | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/TestServiceImpl.java b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/TestServiceImpl.java index d8203fb67..f2c158124 100644 --- a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/TestServiceImpl.java +++ b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/TestServiceImpl.java @@ -636,9 +636,6 @@ public void recalculateDatasets(int testId) { RecalculationStatus status = new RecalculationStatus(RunDAO.count("testid = ?1 AND trashed = false", testId)); // we don't have to care about races with new runs RecalculationStatus prev = recalculations.putIfAbsent(testId, status); - // ensure the recalculation is removed, with this approach we should guarantee - // it gets removed even if transaction-level exception occurs, e.g., timeout - Util.registerTxSynchronization(tm, txStatus -> recalculations.remove(testId, status)); if (prev != null) { log.infof("Recalculation for test %d (%s) already in progress", testId, test.name); return; @@ -652,7 +649,8 @@ public void recalculateDatasets(int testId) { log.debugf("Deleted %d datasets for trashed runs in test %s (%d)", deleted, test.name, (Object) testId); } - try (ScrollableResults results = em + log.infof("Recalculating datasets for test %d (%s)", testId, test.name); + try (ScrollableResults results = em .createNativeQuery("SELECT id FROM run WHERE testid = ?1 AND NOT trashed ORDER BY start") .setParameter(1, testId) .unwrap(NativeQuery.class).setReadOnly(true).setFetchSize(100) diff --git a/horreum-backend/src/main/resources/db/changeLog.xml b/horreum-backend/src/main/resources/db/changeLog.xml index 0644d3b8d..ae409e624 100644 --- a/horreum-backend/src/main/resources/db/changeLog.xml +++ b/horreum-backend/src/main/resources/db/changeLog.xml @@ -4665,4 +4665,27 @@ + + ANY + + -- still need db procedure until https://hibernate.atlassian.net/browse/HHH-17314 is fixed in quarkus + CREATE OR REPLACE PROCEDURE calc_dataset_view(datasetId bigint) AS $$ + BEGIN + WITH view_agg AS ( + SELECT + vc.view_id, vc.id as vcid, array_agg(DISTINCT label.id) as label_ids, jsonb_object_agg(label.name, lv.value) as value FROM dataset_schemas ds + JOIN label ON label.schema_id = ds.schema_id + JOIN viewcomponent vc ON vc.labels ? label.name + JOIN label_values lv ON lv.label_id = label.id AND lv.dataset_id = ds.dataset_id + WHERE ds.dataset_id = datasetId + AND vc.view_id IN (SELECT view.id FROM view JOIN dataset ON view.test_id = dataset.testid WHERE dataset.id = datasetId) + GROUP BY vc.view_id, vcid + ) + INSERT INTO dataset_view (dataset_id, view_id, label_ids, value) + SELECT datasetId, view_id, array_agg(DISTINCT label_id), jsonb_object_agg(vcid, value) FROM view_agg, unnest(label_ids) as label_id + GROUP BY view_id; + END + $$ LANGUAGE plpgsql; + +