[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
This commit is contained in:
Brett Porter 2010-12-30 10:03:44 +00:00
parent 23a09c2024
commit 6e782b161c
2 changed files with 24 additions and 14 deletions

View 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 )

View 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();
}
}