From d6ab28e18977b7d82c8b7edacffa92226a1941fe Mon Sep 17 00:00:00 2001 From: Andrew Hind Date: Mon, 25 Oct 2010 09:40:00 +0000 Subject: [PATCH] Fix for ALF-5032: findAuthorities() getting slow when many groups are created. - moved to PARENT driven queries where possible in preference to PATH git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@23246 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../security/authority/AuthorityDAOImpl.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 2c075262da..ecc50ffdad 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -360,16 +360,38 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } if (parentAuthority != null) { - query.append(" AND PATH:\"/sys:system/sys:authorities/cm:").append(ISO9075.encode(parentAuthority)); - if (!immediate) + if(immediate) { - query.append('/'); + // use PARENT + NodeRef parentAuthorityNodeRef = getAuthorityNodeRefOrNull(parentAuthority); + if(parentAuthorityNodeRef != null) + { + query.append(" AND PARENT:\"").append(LuceneQueryParser.escape(parentAuthorityNodeRef.toString())).append("\""); + } + else + { + throw new UnknownAuthorityException("An authority was not found for " + parentAuthority); + } + } + else + { + // use PATH + query.append(" AND PATH:\"/sys:system/sys:authorities/cm:").append(ISO9075.encode(parentAuthority)); + query.append("//*\""); } - query.append("/*\""); } if (zoneName != null) { - query.append(" AND PATH:\"/sys:system/sys:zones/cm:").append(ISO9075.encode(zoneName)).append("/*\""); + // Zones are all direct links to those within so it is safe to use PARENT to look them up + NodeRef zoneNodeRef = getZone(zoneName); + if (zoneNodeRef != null) + { + query.append(" AND PARENT:\"").append(LuceneQueryParser.escape(zoneNodeRef.toString())).append("\""); + } + else + { + throw new UnknownAuthorityException("A zone was not found for " + zoneName); + } } sp.setQuery(query.toString()); sp.setMaxItems(100);