From 6e782b161c11c1c02a7fb402b018ad26d57f9587 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 30 Dec 2010 10:03:44 +0000 Subject: [PATCH] [MRM-1443, MRM-1327] properly restrict per repository and improve performance git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053840 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultRepositoryStatisticsManager.java | 12 +++++---- .../JcrRepositoryStatisticsGatheringTest.java | 26 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index 2f5f72175..96f48f99c 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -162,7 +162,9 @@ public class DefaultRepositoryStatisticsManager try { QueryManager queryManager = session.getWorkspace().getQueryManager(); - Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact]", Query.JCR_SQL2 ); + String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])"; + Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact] " + whereClause, + Query.JCR_SQL2 ); QueryResult queryResult = query.execute(); @@ -171,7 +173,7 @@ public class DefaultRepositoryStatisticsManager for ( Row row : JcrUtils.getRows( queryResult ) ) { Node n = row.getNode(); - if ( n.getPath().startsWith( "/repositories/" + repositoryId + "/content/" ) ) +// if ( n.getPath().startsWith( "/repositories/" + repositoryId + "/content/" ) ) { totalSize += row.getValue( "size" ).getLong(); @@ -199,11 +201,11 @@ public class DefaultRepositoryStatisticsManager repositoryStatistics.setTotalCountForType( entry.getKey(), entry.getValue() ); } - query = queryManager.createQuery( "SELECT * FROM [archiva:project]", Query.JCR_SQL2 ); + query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 ); repositoryStatistics.setTotalProjectCount( query.execute().getRows().getSize() ); - query = queryManager.createQuery( "SELECT * FROM [archiva:namespace] WHERE namespace IS NOT NULL", - Query.JCR_SQL2 ); + query = queryManager.createQuery( + "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 ); repositoryStatistics.setTotalGroupCount( query.execute().getRows().getSize() ); } catch ( RepositoryException e ) diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java index ece16db48..aeab24040 100644 --- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java +++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java @@ -26,6 +26,7 @@ import org.apache.jackrabbit.core.TransientRepository; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import java.io.File; +import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.zip.GZIPInputStream; @@ -115,15 +116,8 @@ public class JcrRepositoryStatisticsGatheringTest cal.add( Calendar.HOUR, -1 ); Date startTime = cal.getTime(); - Node n = JcrUtils.getOrAddNode( session.getRootNode(), "repositories" ); - n = JcrUtils.getOrAddNode( n, TEST_REPO ); - n = JcrUtils.getOrAddNode( n, "content" ); - n = JcrUtils.getOrAddNode( n, "org" ); - n = JcrUtils.getOrAddNode( n, "apache" ); - - GZIPInputStream inputStream = new GZIPInputStream( getClass().getResourceAsStream( "/artifacts.xml.gz" ) ); - session.importXML( n.getPath(), inputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW ); - session.save(); + loadContentIntoRepo( TEST_REPO ); + loadContentIntoRepo( "another-repo" ); repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO, startTime, endTime, TOTAL_FILE_COUNT, NEW_FILE_COUNT ); @@ -147,4 +141,18 @@ public class JcrRepositoryStatisticsGatheringTest verify( metadataRepository ).addMetadataFacet( TEST_REPO, expectedStatistics ); } + + private void loadContentIntoRepo( String repoId ) + throws RepositoryException, IOException + { + Node n = JcrUtils.getOrAddNode( session.getRootNode(), "repositories" ); + n = JcrUtils.getOrAddNode( n, repoId ); + n = JcrUtils.getOrAddNode( n, "content" ); + n = JcrUtils.getOrAddNode( n, "org" ); + n = JcrUtils.getOrAddNode( n, "apache" ); + + GZIPInputStream inputStream = new GZIPInputStream( getClass().getResourceAsStream( "/artifacts.xml.gz" ) ); + session.importXML( n.getPath(), inputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW ); + session.save(); + } } -- 2.39.5