From 2c1dd1473791be5b9eca9588cd7bb8db4f6cbea2 Mon Sep 17 00:00:00 2001 From: Nicolas Malin Date: Wed, 20 Nov 2024 09:53:30 +0100 Subject: [PATCH] Improved: Optimization on removeJob service (OFBIZ-13182) On removeJob service when we'll remove a job sandbox, we also delete other element linked (RecurrenceInfo and RuntimeData). Before their remove we control that no other job are connected to them, but currently we resolve the list and ensure that it empty. To be fast, we just ask the database through a count and ensure that is zero. --- .../java/org/apache/ofbiz/service/job/JobUtil.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/job/JobUtil.java b/framework/service/src/main/java/org/apache/ofbiz/service/job/JobUtil.java index 7f8b94e9308..ca5e9739310 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/job/JobUtil.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/job/JobUtil.java @@ -18,13 +18,13 @@ *******************************************************************************/ package org.apache.ofbiz.service.job; -import java.util.List; import javax.transaction.Transaction; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.entity.GenericEntityException; import org.apache.ofbiz.entity.GenericValue; import org.apache.ofbiz.entity.transaction.GenericTransactionException; import org.apache.ofbiz.entity.transaction.TransactionUtil; +import org.apache.ofbiz.entity.util.EntityQuery; public final class JobUtil { @@ -43,16 +43,18 @@ public static void removeJob(GenericValue jobValue) { jobValue.remove(); GenericValue relatedValue = jobValue.getRelatedOne("RecurrenceInfo", false); if (relatedValue != null) { - List valueList = relatedValue.getRelated("JobSandbox", null, null, false); - if (valueList.isEmpty()) { + if (EntityQuery.use(jobValue.getDelegator()).from("JobSandbox") + .where("recurrenceInfoId", relatedValue.get("recurrenceInfoId")) + .queryCount() == 0) { relatedValue.remove(); relatedValue.removeRelated("RecurrenceRule"); } } relatedValue = jobValue.getRelatedOne("RuntimeData", false); if (relatedValue != null) { - List valueList = relatedValue.getRelated("JobSandbox", null, null, false); - if (valueList.isEmpty()) { + if (EntityQuery.use(jobValue.getDelegator()).from("JobSandbox") + .where("runtimeDataId", relatedValue.get("runtimeDataId")) + .queryCount() == 0) { relatedValue.remove(); } }