cancel
Showing results for 
Search instead for 
Did you mean: 

Get children of a node faster

spilby
Confirmed Champ
Confirmed Champ
I'm using the alfresco api on my Java backed webscript. I have an uuid, and I do a new NodeRef with this uuid and then I use getChildAssoc from nodeService to obtain all the direct child nodes.


NodeRef nodeRef = new NodeRef("workspace://SpacesStore/" + uuid);
List<ChildAssociationRef> childRefList = new ArrayList<ChildAssociationRef>();
    childRefList = getNodeService().getChildAssocs(nodeRef);

for (ChildAssociationRef childRef : childRefList) {
    NodeRef nodeChildRef = childRef.getChildRef();
    …
}


But on folders with more than 100 subfolders it takes too long. Are there another quicky way to obtain all direct children of a node? The fastest method you know to do that.

Thanks!
5 REPLIES 5

spilby
Confirmed Champ
Confirmed Champ
Any suggestion or idea? I'm still having the problem… Smiley Surprised(

muralidharand
Star Contributor
Star Contributor
Hi,
Can you please provide the server H/W & tomcat configuration as well?

streetturtle
Confirmed Champ
Confirmed Champ
Have you tried using CMIS query for that? There is quite interesting possibility to select by path:


select *
from cmis:document
where contains('PATH:\"/app:company_home/st:sites/cm:MySite/cm:documentLibrary/cm:MyFolder/*"')


You can run this query using
org.alfresco.service.cmr.search.SearchService
or a webscript


/share/proxy/alfresco/slingshot/node/search?q=<query>&lang=cmis-alfresco&store=workspace%3A%2F%2FSpacesStore&maxResults=1000


which is basically the same.


I'm not sure about performance, but I guess it should be slightly better. And you should know exact path to the parent folder.

You can find a bit more info here: http://pavelmakhov.com/2015/10/cmis-path-query/

I'll add when using CMIS, there are some options in the OperationContext you can enable/disable/configure that would also make (sometimes significant) performance improvement.

OperationContext usage example: https://chemistry.apache.org/java/examples/example-list-folder.html

Options: https://chemistry.apache.org/java/0.12.0/maven/apidocs/org/apache/chemistry/opencmis/client/api/Oper...

I don't know if contains is faster for some reason, but CMIS has the IN_FOLDER() clause for this purpose.  So if you have the folder's ID it's simply:
<blockcode>select * from cmis:document where IN_FOLDER('folderid')</blockcode>
Also, generally, don't select * when you only need a few properties (like maybe all you need is cmisSmiley SurprisedbjectId and cmis:name).

Good luck!