mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added helper to ScriptNode to allow scripts to retrieve the short prefix qname version of the list of Aspects for a node, avoiding further processing later.
Modified treenode.get.js to use the faster helper: Test 8x threads x25 repeats - average response time: Before: 280ms After: 170ms git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@47518 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1103,7 +1103,7 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The array of aspects applied to this node
|
* @return The array of aspects applied to this node as fully qualified qname strings
|
||||||
*/
|
*/
|
||||||
public Scriptable getAspects()
|
public Scriptable getAspects()
|
||||||
{
|
{
|
||||||
@@ -1117,6 +1117,31 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
|||||||
return Context.getCurrentContext().newArray(this.scope, result);
|
return Context.getCurrentContext().newArray(this.scope, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The array of aspects applied to this node as short prefix qname strings
|
||||||
|
*/
|
||||||
|
public Scriptable getAspectsShort()
|
||||||
|
{
|
||||||
|
final NamespaceService ns = this.services.getNamespaceService();
|
||||||
|
final Map<String, String> cache = new HashMap<String, String>();
|
||||||
|
final Set<QName> aspects = getAspectsSet();
|
||||||
|
final Object[] result = new Object[aspects.size()];
|
||||||
|
int count = 0;
|
||||||
|
for (final QName qname : aspects)
|
||||||
|
{
|
||||||
|
String prefix = cache.get(qname.getNamespaceURI());
|
||||||
|
if (prefix == null)
|
||||||
|
{
|
||||||
|
// first request for this namespace prefix, get and cache result
|
||||||
|
Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
|
||||||
|
prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
|
||||||
|
cache.put(qname.getNamespaceURI(), prefix);
|
||||||
|
}
|
||||||
|
result[count++] = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName();
|
||||||
|
}
|
||||||
|
return Context.getCurrentContext().newArray(this.scope, result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param aspect The aspect name to test for (fully qualified or short-name form)
|
* @param aspect The aspect name to test for (fully qualified or short-name form)
|
||||||
* @return true if the node has the aspect false otherwise
|
* @return true if the node has the aspect false otherwise
|
||||||
|
Reference in New Issue
Block a user