From 91e5c50435ba6269f1eb5d742dcfd7436b26a0dd Mon Sep 17 00:00:00 2001 From: tiagos Date: Tue, 8 Sep 2020 18:17:55 +0100 Subject: [PATCH 1/2] [MNT-21818] Added cache to records management root, preventing the query from being executed multiple times --- .../rm-service-context.xml | 3 ++ .../fileplan/FilePlanServiceImpl.java | 51 ++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index 00e1ccddaf..757e7649dd 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -393,10 +393,13 @@ + + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java index 1194805168..e9e4f18566 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java @@ -89,6 +89,9 @@ public class FilePlanServiceImpl extends ServiceBaseImpl /** root container cache */ private SimpleCache, NodeRef> rootContainerCache; + /** root records management cache */ + private SimpleCache, Set> rootRecordsManagementCache; + /** File plan role service */ private FilePlanRoleService filePlanRoleService; @@ -174,6 +177,14 @@ public class FilePlanServiceImpl extends ServiceBaseImpl this.rootContainerCache = rootContainerCache; } + /** + * @param rootRecordsManagementCache root records management node cache + */ + public void setRootRecordsManagementCache(SimpleCache, Set> rootRecordsManagementCache) + { + this.rootRecordsManagementCache = rootRecordsManagementCache; + } + /** * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#getFilePlans(org.alfresco.service.cmr.repository.StoreRef) */ @@ -185,20 +196,36 @@ public class FilePlanServiceImpl extends ServiceBaseImpl final Set results = new HashSet<>(); Set aspects = new HashSet<>(1); aspects.add(ASPECT_RECORDS_MANAGEMENT_ROOT); - getNodeDAO().getNodesWithAspects(aspects, Long.MIN_VALUE, Long.MAX_VALUE, new NodeDAO.NodeRefQueryCallback() - { - @Override - public boolean handle(Pair nodePair) - { - NodeRef nodeRef = nodePair.getSecond(); - if (storeRef.equals(nodeRef.getStoreRef())) - { - results.add(nodeRef); - } - return true; + Pair key = new Pair<>(storeRef, ASPECT_RECORDS_MANAGEMENT_ROOT.toString()); + + if (!rootRecordsManagementCache.contains(key)) + { + getNodeDAO().getNodesWithAspects(aspects, Long.MIN_VALUE, Long.MAX_VALUE, new NodeDAO.NodeRefQueryCallback() + { + @Override + public boolean handle(Pair nodePair) + { + NodeRef nodeRef = nodePair.getSecond(); + if (storeRef.equals(nodeRef.getStoreRef())) + { + results.add(nodeRef); + } + + return true; + } + }); + + if (results.size() > 0) + { + rootRecordsManagementCache.put(key, results); } - }); + } + else + { + return rootRecordsManagementCache.get(key); + } + return results; } From 6e119c580c1a11ba1ab38ae60ca97fa5c3bef727 Mon Sep 17 00:00:00 2001 From: tiagos Date: Thu, 10 Sep 2020 11:43:13 +0100 Subject: [PATCH 2/2] [MNT-21818] Added pair key type --- .../org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java index e9e4f18566..9c2379c302 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java @@ -197,7 +197,7 @@ public class FilePlanServiceImpl extends ServiceBaseImpl Set aspects = new HashSet<>(1); aspects.add(ASPECT_RECORDS_MANAGEMENT_ROOT); - Pair key = new Pair<>(storeRef, ASPECT_RECORDS_MANAGEMENT_ROOT.toString()); + Pair key = new Pair(storeRef, ASPECT_RECORDS_MANAGEMENT_ROOT.toString()); if (!rootRecordsManagementCache.contains(key)) {