From f3b014c2b43d85859a2c2becedb4892f092c9048 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 3 Dec 2010 14:19:36 +0000 Subject: [PATCH] [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 git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1041829 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArchivaIndexingTaskExecutor.java | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaIndexingTaskExecutor.java b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaIndexingTaskExecutor.java index 3233a870e..beb4a0da4 100644 --- a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaIndexingTaskExecutor.java +++ b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaIndexingTaskExecutor.java @@ -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 ); -- 2.39.5