Merge pull request #1217 from Alfresco/hotfix-3.2/MNT-21818

[MNT-21818] Added cache to records management root, preventing the query from being executed multiple times
This commit is contained in:
tiagosalvado10
2020-09-10 13:16:53 +01:00
committed by GitHub
2 changed files with 42 additions and 12 deletions

View File

@@ -393,10 +393,13 @@
<bean id="rootContainerCache" class="org.alfresco.repo.cache.DefaultSimpleCache" />
<bean id="rootRecordsManagementCache" class="org.alfresco.repo.cache.DefaultSimpleCache" />
<bean id="filePlanService"
parent="baseService"
class="org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanServiceImpl">
<property name="rootContainerCache" ref="rootContainerCache" />
<property name="rootRecordsManagementCache" ref="rootRecordsManagementCache" />
</bean>
<bean id="FilePlanService" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -89,6 +89,9 @@ public class FilePlanServiceImpl extends ServiceBaseImpl
/** root container cache */
private SimpleCache<Pair<NodeRef, String>, NodeRef> rootContainerCache;
/** root records management cache */
private SimpleCache<Pair<StoreRef, String>, Set<NodeRef>> 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<Pair<StoreRef, String>, Set<NodeRef>> 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<NodeRef> results = new HashSet<>();
Set<QName> 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<Long, NodeRef> nodePair)
{
NodeRef nodeRef = nodePair.getSecond();
if (storeRef.equals(nodeRef.getStoreRef()))
{
results.add(nodeRef);
}
return true;
Pair<StoreRef, String> key = new Pair<StoreRef, String>(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<Long, NodeRef> 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;
}