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

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1041829 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaIndexingTaskExecutor.java

index 3233a870e4c5aec0ca8f15f446445c6bd3217722..beb4a0da46cde036192fbaa2fa0666172a2d79a1 100644 (file)
@@ -19,12 +19,10 @@ package org.apache.maven.archiva.scheduled.executors;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-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.apache.maven.archiva.scheduled.tasks.ArtifactIndexingTask;
 import org.apache.maven.archiva.scheduled.tasks.TaskCreator;
@@ -40,12 +38,14 @@ import org.sonatype.nexus.index.ArtifactContextProducer;
 import org.sonatype.nexus.index.ArtifactInfo;
 import org.sonatype.nexus.index.DefaultArtifactContextProducer;
 import org.sonatype.nexus.index.IndexerEngine;
-import org.sonatype.nexus.index.context.IndexCreator;
 import org.sonatype.nexus.index.context.IndexingContext;
 import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
 import org.sonatype.nexus.index.packer.IndexPacker;
 import org.sonatype.nexus.index.packer.IndexPackingRequest;
 
+import java.io.File;
+import java.io.IOException;
+
 /**
  * ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are
  * all performed by this executor. Add and update artifact in index tasks are added in the indexing task queue by the
@@ -124,23 +124,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 );