From ef085e72d61f2f5fde3eaaf9b8b22fcdb9ebf5f7 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 30 Apr 2022 00:16:12 +0200 Subject: [PATCH] IDEMPIERE-5279 Improve PO to avoid calling cache reset unnecessarily (#1309) --- org.adempiere.base/src/org/compiere/model/PO.java | 11 +++++++---- .../src/org/compiere/util/CacheMgt.java | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index 878b8df8e7..fef7a270a4 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -2538,11 +2538,14 @@ public abstract class PO m_newValues = new Object[size]; m_createNew = false; } - if (!newRecord) { - Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().reset(p_info.getTableName(), get_ID())); + if (!newRecord) MRecentItem.clearLabel(p_info.getAD_Table_ID(), get_ID()); - } else if (get_ID() > 0 && success) - Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().newRecord(p_info.getTableName(), get_ID())); + if (CacheMgt.get().hasCache(p_info.getTableName())) { + if (!newRecord) + Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().reset(p_info.getTableName(), get_ID())); + else if (get_ID() > 0 && success) + Adempiere.getThreadPoolExecutor().submit(() -> CacheMgt.get().newRecord(p_info.getTableName(), get_ID())); + } return success; } // saveFinish diff --git a/org.adempiere.base/src/org/compiere/util/CacheMgt.java b/org.adempiere.base/src/org/compiere/util/CacheMgt.java index 2e59f6827e..454c38b0bf 100644 --- a/org.adempiere.base/src/org/compiere/util/CacheMgt.java +++ b/org.adempiere.base/src/org/compiere/util/CacheMgt.java @@ -478,4 +478,14 @@ public class CacheMgt } } } + + /** + * Is there a cache for this table name? + * @param tableName + * @return boolean + */ + public boolean hasCache(String tableName) { + return m_tableNames.contains(tableName); + } + } // CCache