mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
. Optimize ApplicationScriptUtils.toJSON() - threadlocal cache for namespace resolution to avoid DD access, smarter retrieval of cm:person properties - 40% quicker or more in some cases
. Convert short qnames to long qnames in our templates to avoid DD access to resolve full qnames . Optimize out N+1 queries from calling RatingService.getRating() unless the document has at least one Like (which is available in the rolled up property already present on the node) - up to 99% quicker when building "Likes" JSON structure...! . Added new optimized method to FileFolderService to retrieve a cm:name based path - only the String for each path element not the full FileInfo structure for each (avoid full getProperties() - 70% quicker to build webdav URL overall before/after to retrieve doclist2 script (8x concurrent threads x25 repeats etc.) Before: 1030ms After: 645ms Also improves original doclist script (used by dashlets) and single node retrievals. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@47448 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1303,6 +1303,22 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
return FileFolderUtil.makeFolders(service, parentNodeRef, pathElements, folderTypeQName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file or folder information from the root down to and including the node provided.
|
||||
* <ul>
|
||||
* <li>The root node can be of any type and is not included in the path list.</li>
|
||||
* <li>Only the primary path is considered. If the target node is not a descendant of the
|
||||
* root along purely primary associations, then an exception is generated.</li>
|
||||
* <li>If an invalid type is encountered along the path, then an exception is generated.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param rootNodeRef the start of the returned path, or null if the <b>store</b> root
|
||||
* node must be assumed.
|
||||
* @param nodeRef a reference to the file or folder
|
||||
* @return Returns a list of file/folder infos from the root (excluded) down to and
|
||||
* including the destination file or folder
|
||||
* @throws FileNotFoundException if the node could not be found
|
||||
*/
|
||||
public List<FileInfo> getNamePath(NodeRef rootNodeRef, NodeRef nodeRef) throws FileNotFoundException
|
||||
{
|
||||
// check the root
|
||||
@@ -1334,13 +1350,13 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
continue;
|
||||
}
|
||||
// we found the root and expect to be building the path up
|
||||
//Run as system as the user could not have access to all folders in the path, see ALF-13816
|
||||
// Run as system as the user could not have access to all folders in the path, see ALF-13816
|
||||
FileInfo pathInfo = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<FileInfo>()
|
||||
{
|
||||
public FileInfo doWork() throws Exception
|
||||
{
|
||||
return toFileInfo(childNodeRef, true);
|
||||
}
|
||||
public FileInfo doWork() throws Exception
|
||||
{
|
||||
return toFileInfo(childNodeRef, true);
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
|
||||
// we can't append a path element to the results if there is already a (non-folder) file at the tail
|
||||
@@ -1372,6 +1388,85 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
throw new FileNotFoundException(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file or folder names from the root down to and including the node provided.
|
||||
* <ul>
|
||||
* <li>The root node can be of any type and is not included in the path list.</li>
|
||||
* <li>Only the primary path is considered. If the target node is not a descendant of the
|
||||
* root along purely primary associations, then an exception is generated.</li>
|
||||
* <li>If an invalid type is encountered along the path, then an exception is generated.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param rootNodeRef the start of the returned path, or null if the <b>store</b> root
|
||||
* node must be assumed.
|
||||
* @param nodeRef a reference to the file or folder
|
||||
* @return Returns a list of file/folder names from the root (excluded) down to and
|
||||
* including the destination file or folder
|
||||
* @throws FileNotFoundException if the node could not be found
|
||||
*/
|
||||
public List<String> getNameOnlyPath(NodeRef rootNodeRef, final NodeRef nodeRef) throws FileNotFoundException
|
||||
{
|
||||
// check the root
|
||||
if (rootNodeRef == null)
|
||||
{
|
||||
rootNodeRef = nodeService.getRootNode(nodeRef.getStoreRef());
|
||||
}
|
||||
try
|
||||
{
|
||||
final NodeRef rNodeRef = rootNodeRef;
|
||||
final ArrayList<String> results = new ArrayList<String>(10);
|
||||
// Run as system as the user could not have access to all folders in the path, see ALF-13816
|
||||
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
// get the primary path
|
||||
Path path = nodeService.getPath(nodeRef);
|
||||
// iterate and turn the results into file info objects
|
||||
boolean foundRoot = false;
|
||||
for (Path.Element element : path)
|
||||
{
|
||||
// ignore everything down to the root
|
||||
Path.ChildAssocElement assocElement = (Path.ChildAssocElement) element;
|
||||
final NodeRef childNodeRef = assocElement.getRef().getChildRef();
|
||||
if (childNodeRef.equals(rNodeRef))
|
||||
{
|
||||
// just found the root - but we don't put in an entry for it
|
||||
foundRoot = true;
|
||||
continue;
|
||||
}
|
||||
else if (!foundRoot)
|
||||
{
|
||||
// keep looking for the root
|
||||
continue;
|
||||
}
|
||||
results.add(nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME).toString());
|
||||
}
|
||||
// check that we found the root
|
||||
if (!foundRoot)
|
||||
{
|
||||
throw new FileNotFoundException(nodeRef);
|
||||
}
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Built name path for node: \n" +
|
||||
" root: " + rNodeRef + "\n" +
|
||||
" node: " + nodeRef + "\n" +
|
||||
" path: " + results);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
|
||||
return results;
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
throw new FileNotFoundException(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
public FileInfo resolveNamePath(NodeRef rootNodeRef, List<String> pathElements) throws FileNotFoundException
|
||||
{
|
||||
|
@@ -839,6 +839,36 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetNameOnlyPath() throws Exception
|
||||
{
|
||||
FileInfo fileInfo = getByName(NAME_L1_FILE_A, false);
|
||||
assertNotNull(fileInfo);
|
||||
NodeRef nodeRef = fileInfo.getNodeRef();
|
||||
|
||||
List<String> infoPaths = fileFolderService.getNameOnlyPath(workingRootNodeRef, nodeRef);
|
||||
assertEquals("Not enough elements", 2, infoPaths.size());
|
||||
assertEquals("First level incorrent", NAME_L0_FOLDER_A, infoPaths.get(0));
|
||||
assertEquals("Second level incorrent", NAME_L1_FILE_A, infoPaths.get(1));
|
||||
|
||||
// pass in a null root and make sure that it still works
|
||||
infoPaths = fileFolderService.getNameOnlyPath(null, nodeRef);
|
||||
assertEquals("Not enough elements", 3, infoPaths.size());
|
||||
assertEquals("First level incorrent", workingRootNodeRef.getId(), infoPaths.get(0));
|
||||
assertEquals("Second level incorrent", NAME_L0_FOLDER_A, infoPaths.get(1));
|
||||
assertEquals("Third level incorrent", NAME_L1_FILE_A, infoPaths.get(2));
|
||||
|
||||
// check that a non-aligned path is detected
|
||||
NodeRef startRef = getByName(NAME_L0_FOLDER_B, true).getNodeRef();
|
||||
try
|
||||
{
|
||||
fileFolderService.getNameOnlyPath(startRef, nodeRef);
|
||||
fail("Failed to detect non-aligned path from root to target node");
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetNamePathDoesNotReturnPathContainingNonLeafFileNode() throws Exception
|
||||
{
|
||||
|
Reference in New Issue
Block a user