[MRM-1439] improve indexing performance

Avoid re-reading the entire index each time an artifact is added, and instead search to see if it should be added or updated
Merged from: r1041829


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1041846 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2010-12-03 15:01:20 +00:00
parent c6e3bb8463
commit 23ebf87131
1 changed files with 8 additions and 19 deletions

View File

@ -22,8 +22,10 @@ package org.apache.archiva.scheduler.indexing;
import java.io.File;
import java.io.IOException;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
@ -120,23 +122,10 @@ public class ArchivaIndexingTaskExecutor
{
if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
{
boolean add = true;
IndexReader r = context.getIndexReader();
for ( int i = 0; i < r.numDocs(); i++ )
{
if ( !r.isDeleted( i ) )
{
Document d = r.document( i );
String uinfo = d.get( ArtifactInfo.UINFO );
if ( ac.getArtifactInfo().getUinfo().equals( uinfo ) )
{
add = false;
break;
}
}
}
if ( add )
IndexSearcher s = context.getIndexSearcher();
String uinfo = ac.getArtifactInfo().getUinfo();
TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );
if ( d.totalHits == 0 )
{
log.debug( "Adding artifact '" + ac.getArtifactInfo() + "' to index.." );
indexerEngine.index( context, ac );