mirror of https://github.com/apache/archiva.git
[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:
parent
23a09c2024
commit
6e782b161c
|
@ -162,7 +162,9 @@ public class DefaultRepositoryStatisticsManager
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QueryManager queryManager = session.getWorkspace().getQueryManager();
|
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();
|
QueryResult queryResult = query.execute();
|
||||||
|
|
||||||
|
@ -171,7 +173,7 @@ public class DefaultRepositoryStatisticsManager
|
||||||
for ( Row row : JcrUtils.getRows( queryResult ) )
|
for ( Row row : JcrUtils.getRows( queryResult ) )
|
||||||
{
|
{
|
||||||
Node n = row.getNode();
|
Node n = row.getNode();
|
||||||
if ( n.getPath().startsWith( "/repositories/" + repositoryId + "/content/" ) )
|
// if ( n.getPath().startsWith( "/repositories/" + repositoryId + "/content/" ) )
|
||||||
{
|
{
|
||||||
totalSize += row.getValue( "size" ).getLong();
|
totalSize += row.getValue( "size" ).getLong();
|
||||||
|
|
||||||
|
@ -199,11 +201,11 @@ public class DefaultRepositoryStatisticsManager
|
||||||
repositoryStatistics.setTotalCountForType( entry.getKey(), entry.getValue() );
|
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() );
|
repositoryStatistics.setTotalProjectCount( query.execute().getRows().getSize() );
|
||||||
|
|
||||||
query = queryManager.createQuery( "SELECT * FROM [archiva:namespace] WHERE namespace IS NOT NULL",
|
query = queryManager.createQuery(
|
||||||
Query.JCR_SQL2 );
|
"SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 );
|
||||||
repositoryStatistics.setTotalGroupCount( query.execute().getRows().getSize() );
|
repositoryStatistics.setTotalGroupCount( query.execute().getRows().getSize() );
|
||||||
}
|
}
|
||||||
catch ( RepositoryException e )
|
catch ( RepositoryException e )
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.jackrabbit.core.TransientRepository;
|
||||||
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
|
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
@ -115,15 +116,8 @@ public class JcrRepositoryStatisticsGatheringTest
|
||||||
cal.add( Calendar.HOUR, -1 );
|
cal.add( Calendar.HOUR, -1 );
|
||||||
Date startTime = cal.getTime();
|
Date startTime = cal.getTime();
|
||||||
|
|
||||||
Node n = JcrUtils.getOrAddNode( session.getRootNode(), "repositories" );
|
loadContentIntoRepo( TEST_REPO );
|
||||||
n = JcrUtils.getOrAddNode( n, TEST_REPO );
|
loadContentIntoRepo( "another-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();
|
|
||||||
|
|
||||||
repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO, startTime, endTime,
|
repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO, startTime, endTime,
|
||||||
TOTAL_FILE_COUNT, NEW_FILE_COUNT );
|
TOTAL_FILE_COUNT, NEW_FILE_COUNT );
|
||||||
|
@ -147,4 +141,18 @@ public class JcrRepositoryStatisticsGatheringTest
|
||||||
|
|
||||||
verify( metadataRepository ).addMetadataFacet( TEST_REPO, expectedStatistics );
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue