cancel
Showing results for 
Search instead for 
Did you mean: 

Performance issues - getChildAssocs alternatives

dave984
Champ in-the-making
Champ in-the-making
Hi all, referring to the Alfresco NodeRef cookbook i retrieve all the files existing in a folder in this way:

List<ChildAssociationRef> filesFolderList = nodeService.getChildAssocs(folderNodeRef);
for (ChildAssociationRef file : filesFolderList) {
  NodeRef childRef = file.getChildRef();
  FileInfo fileInfo = fileFolderService.getFileInfo(childRef);
  if(fileInfo != null && !nodeService.hasAspect(childRef, Prop.MY_ASPECT)
     && !nodeService.hasAspect(childRef, Prop.MY_SECOND_ASPECT)
     && !fileInfo.isFolder()
     && !childRef.equals(actualDocumentRef)){          
    //do something
  }
}


This works, but if the folder contains something like 1500 files we notice a deep performance slowdown.
Is there a way to optimize this?Do you have some suggestions?

6 REPLIES 6

afaust
Legendary Innovator
Legendary Innovator
Hello,

the problem is not really with getChildAssocs but your use of it. For one thing, it is very expensive to call getFileInfo before you have even checked the aspect - moving this inside of the then-block of the if-clause should improve performance quite a bit. Also, there are overloaded variants of getChildAssocs() that you could use e.g. if you want to look for specific association types or names - of course that requires you to actually have some distinct association types and not just use cm:contains.
If transactional consistency is not of concern to you, you could also use a FTS query with PATH and ASPECT selectors (via SearchService) to retrieve the relevant files.

In the end, you should also ask yourself the question if it is wise to have 1500 files in one folder when you need to retrieve some of them using a condition that cannot be easily checked during iteration.

Regards
Axel

dave984
Champ in-the-making
Champ in-the-making
Hi Axel thank you for your answer.
I'm really sorry, i minimized the if-clause beacause i didn't think getFileInfo could be so expensive. I edited my initial question with the full if-clause…what do you think now?
Transactional consistency is important for what i'm doing so i cannot use a Lucene Query…

mrogers
Star Contributor
Star Contributor
This version of the getChildAssocs(NodeRef nodeRef, Set<QName> childNodeTypeQNames);  could help by filtering out folders before you get them.

And you may be able to use the search service for database backed queries.

dave984
Champ in-the-making
Champ in-the-making
Roger thank you for your suggestion…i'm trying to use getChildAssocs as follow but without success:

Set<QName> types = new HashSet<QName>(1, 1.0f);
types.add(ContentModel.TYPE_CONTENT);
List<ChildAssociationRef> filesFolderList = nodeService.getChildAssocs(parentNodeRef, types);


it returns me zero results neither files nor folders…

dave984
Champ in-the-making
Champ in-the-making
Someone knows how to use getChildAssocs(NodeRef nodeRef, Set childNodeTypeQNames); ?
My code returns 0 elements in the folder and that's not right of course!

sanket
Champ on-the-rise
Champ on-the-rise
Are you sure that inside your parentNodeRef folder, all are content types. If you have deployed your custom model, then there can be custom content types present inside it.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.