]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1439] improve indexing performance
authorBrett Porter <brett@apache.org>
Fri, 3 Dec 2010 15:01:20 +0000 (15:01 +0000)
committerBrett Porter <brett@apache.org>
Fri, 3 Dec 2010 15:01:20 +0000 (15:01 +0000)
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

archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java

index f6c77ba30371374cfaa3d991d1e44b648534b8a6..c4a3e2f32005a21aaacb2b7bb802b41a55ae00aa 100644 (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 );