cancel
Showing results for 
Search instead for 
Did you mean: 

Another method more efficient than getChildAssocsByPropertyValue?

spilby
Confirmed Champ
Confirmed Champ
Good morning,

before I create a new folder on a path, I need to know if the title of this folder exists on that path.

I do this to check it:


   List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
   assocs = getNodeService().getChildAssocsByPropertyValue(nodeRef, 
               QName.createQName(Constants.modelAlfrescoNS, Constants.titleProperty), titleFolder);
   if (assocs==null || assocs.isEmpty()) {
       // A folder with this title not exists
       …
   }


At first this works ok, but now that I have a lot of folders, I can see that this operation takes too long (for example, a path with 40 folders takes up to 6 seconds to return the assocs, with a 1.500.000 documents on all alfresco system).

Are there another method to know it better than getChildAssocsByPropertyValue? I don't need to explore recursively on subfolders, only explore the direct sons of a folder to not repeat a title.

And I prefer not use a lucene search, because of I need to create a lot of classes quickly and some times a lucene search don't give me a result because it's not indexed yet.

Thank you very much!
4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator
Hello,

quick question first: You do know there is a ContentModel.PROP_TITLE constant already provided by Alfresco for use as a QName, right?

In regards to your actual question: Why don't you use the title value and store it under the name property? If it must be unique, then it is better suited as cm:name. This would allow you to use getChildByName which is a bit more optimized in the DB query.

Other than using a different property: Have you enabled the <a href="http://docs.alfresco.com/4.2/concepts/intrans-metadata-conf-patch.html">metadata query index patch</a> so Alfresco creates optional DB indices? This may also impact your performance quite a bit.

Regards
Axel

spilby
Confirmed Champ
Confirmed Champ
Thanks for the response, AFaust.

First of all, no, I don't use ContentModel.PROP_TITLE. Only PROP_NAME. When I create a node, I do this


   properties.put(ContentModel.PROP_NAME, nodeName);
   nodeRef = getNodeService().createNode(parent,
       ContentModel.ASSOC_CONTAINS,
       QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName),
       myCustomType,
       properties).getChildRef();

    if (nodeRef!=null) {
       QName CUSTOM_ASPECT_QNAME = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, Constants.aspectTitled);
       Map<QName,Serializable> aspectValues = new HashMap<QName,Serializable>();
       aspectValues.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, Constants.titleProperty), myTitleName);
       aspectValues.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, Constants.descriptionProperty), myDescription);
       getNodeService().addAspect(nodeRef, CUSTOM_ASPECT_QNAME, aspectValues);
    }


I put the title on the aspect. Doing this, I can see in the properties of the node created the value myTitleName on {http://www.alfresco.org/model/content/1.0}title and I supossed that was correct.

Isn't correct? I should add something like the following line on my code?


properties.put(ContentModel.PROP_TITLE, myTitleName)


Or is the same?

And about the second recommendation, on our alfresco-global.properties not appears any system.metadata-query-indexes.ignored. I was'nt aware of this property so far. To enable this the value is false?

Thanks again!

spilby
Confirmed Champ
Confirmed Champ
I'm doing some tests setting ContentModel.PROP_TITLE or setting the aspectTitled (code wrote before). The result is the same, both ways set the title on {http://www.alfresco.org/model/content/1.0}title property.

Anyone knows if is really the same? Both ways are correct? In terms of performance too.

And the system.metadata-query-indexes.ignored property should be false or true?

If all is ok, I need a alternative to getChildAssocsByPropertyValue like I expose on the fisrt message, please, the result time takes too long.

Thanks again.

Best regards




afaust
Legendary Innovator
Legendary Innovator
Hello,

using PROP_TITLE is fully identical. This is due to the fact that the QName you manually construct consists of the same components that are used in constructing the constant.
You know, you can also merge the createNode with the addAspect into one call to createNode by putting the aspect properties in the same properties map you put PROP_NAME into. Alfresco will automatically add the aspect when you use any of its properties, so there is no need for an extra addAspect call.

system.metadata-query-indexes.ignored should be "false" to ensure your DB has the extra indices to potentially improve performance. But as I said, using PROP_NAME for the unique value you perform lookups by (using getChildByName) may be the best option for better performance.

You might also want to try logging the individual SQL used to lookup the node and look at the individual durations. Then if you find a specific SQL that is taking too long, you can have your RDBMS explain the query plan to you. Using <a href="https://wiki.alfresco.com/wiki/Driver-side_DB_Query_Profiling">driver-side logging via p6spy</a> is a good place to start…

Regards
Axel