mirror of https://github.com/apache/archiva.git
[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:
parent
c6e3bb8463
commit
23ebf87131
|
@ -22,8 +22,10 @@ package org.apache.archiva.scheduler.indexing;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.index.IndexReader;
|
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.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||||
|
@ -120,23 +122,10 @@ public class ArchivaIndexingTaskExecutor
|
||||||
{
|
{
|
||||||
if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
|
if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
|
||||||
{
|
{
|
||||||
boolean add = true;
|
IndexSearcher s = context.getIndexSearcher();
|
||||||
IndexReader r = context.getIndexReader();
|
String uinfo = ac.getArtifactInfo().getUinfo();
|
||||||
for ( int i = 0; i < r.numDocs(); i++ )
|
TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );
|
||||||
{
|
if ( d.totalHits == 0 )
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
log.debug( "Adding artifact '" + ac.getArtifactInfo() + "' to index.." );
|
log.debug( "Adding artifact '" + ac.getArtifactInfo() + "' to index.." );
|
||||||
indexerEngine.index( context, ac );
|
indexerEngine.index( context, ac );
|
||||||
|
|
Loading…
Reference in New Issue