]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1443, MRM-1327] properly restrict per repository and improve performance
authorBrett Porter <brett@apache.org>
Thu, 30 Dec 2010 10:03:44 +0000 (10:03 +0000)
committerBrett Porter <brett@apache.org>
Thu, 30 Dec 2010 10:03:44 +0000 (10:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053840 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java

index 2f5f7217500cb54222760624e28560eddc7e254d..96f48f99ce7b835c492fa2ea371aabc1d31acdb0 100644 (file)
@@ -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 )
index ece16db485196691ca74eaadcba75bc6cb2c1a68..aeab2404074492adb94b53d32efbbac8722d4815 100644 (file)
@@ -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();
+    }
 }