cancel
Showing results for 
Search instead for 
Did you mean: 

How get first children with FTL

spilby
Confirmed Champ
Confirmed Champ
I have a performance time problem with a custom webscript that I'm doing.

The webscript only search a node by uuid and return a JSON with some properties of the children of this node, and return the number of the subchilds of them too.

I do this in my js:


  function main()
{
    var node = [];
    node = search.findNode("workspace://SpacesStore/"+args["uuid"]);
    model.childResults = node.children;
} main();


And on my FTL I do this:


<#macro parseChild objectModel>
   <#assign loop = 0 />
   <#list objectModel as child>
      <#if (loop > 0) >, </#if>
      {
        "ID" : "${child.id}",
         "PROP_NAME" : "${child.properties["name"]}",
         <#if child.properties["cf:author"]?exists>
            "AUTHOR" : "${child.properties["cf:author"]}",
         </#if>
         <#if child.properties["cf:data_cf"]?exists>
            "PROP_CREATED" : "${xmldate(child.properties["cf:date_cf"]?datetime)}",
         </#if>
         "TYPE" : "${child.type}",
              "NUMBER_CHILDS" : ${child.children?size}

      <#assign loop = loop + 1 />
      }
   </#list>
</#macro>

<#if (childResults?size > 0)>
{
   "nodes" :
   [
      <@parseChild childResults/>
   ]
}
<#else>
   Empty
</#if>


The problem is… I have over 200 folders on the node, and each one have 30 or 40 subfolders too. And when I do child.children?size the webscript takes a lot of time.

Are there any quickly way to know the number of childs on this 200 folders? child.children takes too long.

If this methos don't exists, I have another possibility. Returns only a parameter that gives me if each of this 200 folders have at least one children. For this, I only need to obtain a children of each one. How can I do this? What method can I apply to each child to obtain the first child or know if this child have a child?

Thank you very much!
1 REPLY 1

muralidharand
Star Contributor
Star Contributor
Hi,
I don't have that much data to reproduce your issue, but try the below one. Store the size in another variable and try something like the below one



function main()
{
    var node = [];
    node = search.findNode("workspace://SpacesStore/"+args["uuid"]);
    model.childResults = node.children;
    model.childResultsSize = node.children.length;
} main();





<#macro parseChild objectModel>
   <#assign loop = 0 />
   <#list objectModel as child>
      <#if (loop > 0) >, </#if>
      {
        "ID" : "${child.id}",
         "PROP_NAME" : "${child.properties["name"]}",
         <#if child.properties["cf:author"]?exists>
            "AUTHOR" : "${child.properties["cf:author"]}",
         </#if>
         <#if child.properties["cf:data_cf"]?exists>
            "PROP_CREATED" : "${xmldate(child.properties["cf:date_cf"]?datetime)}",
         </#if>
         "TYPE" : "${child.type}",
              "NUMBER_CHILDS" : ${child.children?size}

      <#assign loop = loop + 1 />
      }
   </#list>
</#macro>

<#if (childResultsSize > 0)>
{
   "nodes" :
   [
      <@parseChild childResults/>
   ]
}
<#else>
   Empty
</#if>


Still if you have the performance problem, then  you write your own Java backed webscript and use nodeService to fetch items which may be faster than search ones.